How to embed images in html and send html as email using msdb.dbo.sp_send_dbmail?

I can use msdb.dbo.sp_send_dbmail to send html email. This is very good for text only in terms of format. For instance:

EXEC msdb.dbo.sp_send_dbmail @recipients = @p_recipients, @subject = @v_subject, @ body=@emailHTML , @body_format = 'HTML'; 

However, if I want to include images, such as trends, created from data on my SQL server, and embed them in html (@emailHTML), which html tag should I use?

If I use the [img] tag, then I need to set the src attribute. The generated image is saved on my local SQL Server hard drive. I could place them in the web page area of ​​the IS server. But all these web servers are available within the network, but not outside of my work.

Is there a way to insert an image in an email? How can I install html for embedding images?

I use Microsoft SQL Server 2005. I prefer msdb.dbo.sp_send_dbmail to send reports as email. I have a lot of control over the html format. If this is not the case, I may need to send the images as attachment files.

+4
source share
1 answer

I think I got the answer:

 EXEC msdb.dbo.sp_send_dbmail @recipients = ' myemail@someemail.com ', @subject = 'test', @file_attachments = 'C:\MyFolder\Test\Google.gif;C:\MyFolder\Test\Yahoo.gif', @body=N'<p>Image Test</p><img src="Google.gif" /><p>See image there?</p> <img src="Yaoo.gif" /><p>Yahoo!</p>', @body_format = 'HTML'; 

basically, add the image as an attachment, and the src attribute contains only the image file name, no path is required. If multiple image files are required, simply use ";" to separate them.

I am sending an email to my email address and it works. Try contacting my email address ....

+12
source

All Articles