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)
 mail attachment

Author  Topic 

DBA007
Posting Yak Master

145 Posts

Posted - 2010-02-08 : 16:15:51
HI,
does any one have idea on sending the sqljob output as a mail attachment.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-02-08 : 16:34:54
You can send attachments via Database Mail.

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

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

DBA007
Posting Yak Master

145 Posts

Posted - 2010-02-09 : 06:15:07
thanks tara,
but i need the tsql to be used in the job for sending the job output as a mail attachment,the first step of the job executes a script and writes to a file,and the second step has to send this output as a mail attachment.the job must also delete the contents of the output file every time it runs.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-02-09 : 20:04:35
But you can get to Database Mail via TSQL, so I'm not understanding what the issue is.

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

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

vmenon
Starting Member

17 Posts

Posted - 2010-02-11 : 06:27:37
Step 1 of Agent job executes a script ans writes to a file e.g. c:\QueryOutput.txt
Step 2 of Agent job needs to excute the below query to send the attachment mail.

To send e-mail in Plain Text and also attachements:

EXEC sp_send_dbmail
@recipients = 'SQLDBA@dba.com',
@subject = 'Please find the QueryOutput',
@body = 'Please find the QueryOutput in the attached file',
@body_format = 'TEXT',
@file_attachments = 'c:\QueryOutput.txt'


To send e-mail in MIME and also attachements:
EXEC sp_send_dbmail
@recipients = 'SQLDBA@dba.com',
@subject = 'Please find the QueryOutput',
@body = 'Please find the QueryOutput in the attached file',
@body_format = 'HTML',
@file_attachments = 'c:\QueryOutput.txt'
Go to Top of Page
   

- Advertisement -