Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Database Mail and MSDB

Author  Topic 

andyc209
Starting Member

5 Posts

Posted - 2010-07-30 : 11:40:28
I have Database mail configured and working from the MSDB database, however I want to run queries out of another database and send these out on Email - excuse my ignorance but how can i get Database Mail to work from another database (all my data is in database called MYDATA) but when I change the 'use [MSDB]' to 'use [MYDATA]' obviously all the Stored Procs to do with Database Mail are missing.

any help for a novice is much appreciated

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-07-30 : 11:46:04
That's not how it works. Database Mail runs from msdb. You can have it execute queries in other databases via @execute_query_database input parameter. Check BOL for details.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

kenchee
Starting Member

49 Posts

Posted - 2010-08-02 : 20:48:33
Hi,
the query that you use on the other database, what you can do is to use this sql command
EXEC msdb.dbo.sp_send_dbmail
@profile_name = <database mail profile>,
@recipients = <email address of the recipient>,
@copy_recipients = <cc email address>,
@subject = <email subject>,
@body = <email message>,
@body_format = <can be html or text>

The other thing to check is to ensure the user you are using to execute this query has permissions to "DatabaseMailUserRole" in the msdb database.

hope this helps
Go to Top of Page
   

- Advertisement -