开发者

How to embed images in e-mails sent by msdb.dbo.sp_send_dbmail?

I'm trying to send e-mails to contacts stored in SQL Server database. The e-mails contain images.

EXEC msdb.dbo.sp&#95;send&#95;dbmail<br/>
   @recipients = 'name@address.com;',<br/>
   @subject = 'Sending Mail from SQL Server Test',<br/>
   @file_attachments = 'C:\inetpub\wwwroot\pagerror.gif',<br/>
   @body=N'&lt;img src="pagerror.gif" /&gt;',<br/> 
   @body_format = 'HTML';

but some e-mail providers (like Yahoo) assume the sent mail as spam. What i need is to create the <img> tag like the ones generated by Outlook:

<img wi开发者_运维百科dth=482 height=675 id="_x0000_i1025" src="cid:image002.png@01CA4B5E.28AE48C0">

With this tag, Yahoo doesn't assume it as spam. How to process the image so I can refer it like above?

I'm not an advanced SQL Server programmer. I really need a step-by-step tutorial. Please help...


If the image resides on another server and you are just referring to it in your mail, then follow Jonathans comment.

If sending image as attachment is fine, you could use something like this...

EXEC msdb.dbo.sp_send_dbmail
    @recipients = 'name@address.com;',
    @subject = 'Sending Mail from SQL Server Test',
    @body_format = 'HTML',
    @query = 'SELECT imageField FROM Person WHERE ID = 12345',
    @execute_query_database = 'YourDatabase',
    @attach_query_result_as_file = 1,
    @query_attachment_filename = 'imageOfAPerson.jpg'

If nothing of the kind is good for you, you can use CLR functionality of SQL server and develop your own piece of code to send an arbitrary email. I believe you don't have a clue how to do it and it can be rather complex, but that's how it is. There is no easy way around it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜