By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,313 Members | 1,240 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,313 IT Pros & Developers. It's quick & easy.

Sending file contents in the body of the email with xp_sendmail

P: n/a
I would like to send the contents of a file using xp_sendmail however
I do not want the file contents to be an attachment.
I have no problem sending the file as an attachement.
Can anybody give me an xp_sendmail example of how to do this.
The results of a query can easily appear in the body of the email but
all my
attempts to include the contents of a file in the body of the email
have not worked.

TIA
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Michael McGarrigle" <mj*@barwonwater.vic.gov.au> wrote in message
news:9d**************************@posting.google.c om...
I would like to send the contents of a file using xp_sendmail however
I do not want the file contents to be an attachment.
I have no problem sending the file as an attachement.
Can anybody give me an xp_sendmail example of how to do this.
The results of a query can easily appear in the body of the email but
all my
attempts to include the contents of a file in the body of the email
have not worked.

TIA


Rather than use xp_sendmail, you could check out xp_smtp_sendmail:

http://www.sqldev.net/xp/xpsmtp.htm

It has a @messagefile parameter which looks like it may do what you want.
Otherwise, you can use xp_cmdshell to read the file into a table, then query
the table to get the message body:

create table ##t (col1 varchar(1000))
insert into ##t exec master..xp_cmdshell 'type c:\myfile.txt'
exec master..xp_sendmail
@recipients = 's******@somewhere.com',
@query = 'select col1 from ##t'
...

This is quite similar to example E for xp_sendmail in Books Online.

Simon
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.