How do I insert images into emails sent with msdb.dbo.sp_send_dbmail?

I am trying to send emails to contacts stored in a SQL Server database. Emails 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';

      

however, some email providers (such as Yahoo) accept the sent email as spam. I need to create <img> like the ones generated by Outlook:

<img width = 482 height = 675 id = "_ x0000_i1025" src = "cid: image002.png@01CA4B5E.28AE48C0 " </p>

With this tag, Yahoo does not consider it spam. How do I process the image so that I can link to it like above?

I am not a SQL Server programmer. I really need a step by step guide. Please, help...

+2


source to share


1 answer


If the image is on a different server and you're just linking to it in your mail, follow Jonathan's comments.

If sending the image as an attachment is ok, you can 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 none of this suits you, you can use the CLR functionality of the SQL Server and develop your own code to send an arbitrary email. I believe you don't know how to do this and it can be quite tricky, but it is. There is no easy way around it.

0


source







All Articles