SQL Server - Embed image in html and send html as email

Asked By Naresh Kumar on 24-Nov-11 05:22 AM
Can any one knows how to embed image in html and send html as email by msdb.dbo.sp_send_dbmail .

Please advise.
Jitendra Faye replied to Naresh Kumar on 24-Nov-11 05:25 AM
Try like this-

declare @body1 varchar(4000)
set @body1 = '<head>
<title> Embedded Logo Example</title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<table><tr><td valign="top" align="left">MyHeader</td></tr>
<tr><td valign="top" align="left"><img src="cid:sqlservercentral_logo.gif" width="235" height="70" border="0" alt="">

EXEC msdb.dbo.sp_send_dbmail
='MyDefault EmailProfile',

= 'SQl 2008 email test',
= @body1,
= 'HTML',
= 'SELECT top 3 * from sysobjects where xtype=''U''',
= 0,
= 1,
= 1,
= 1,
= 'results.txt',
= 1,
= 'C:\sqlservercentral_logo.gif'
Deepak More replied to Jitendra Faye on 11-Nov-13 10:37 AM
I tried this trick. but It didnt work for me.

it actually show a file attachment. image is not loading in img tag using cid. 
when i inspect that elemnt there i found that src attribute is getting lost.