1

I am using sp_send_dbmail in SQL Server 2008 to send out an HTML email. I can reference to image with url like <img src="http:..." />

I have attached the image with the @file_attachments. How to reference to this image in attachment?

Dale K
  • 25,246
  • 15
  • 42
  • 71
Squirrel
  • 23,507
  • 4
  • 34
  • 32
  • Possible duplicate of [Can an HTML email body reference...an attachment...](http://stackoverflow.com/questions/9983248/can-an-html-email-body-reference-a-file-sent-as-an-attachment-in-the-same-email) – John Dewey Apr 12 '12 at 03:47
  • I am doing this in SQL Server t-sql. How to get that "Content-ID" "" ? – Squirrel Apr 12 '12 at 03:55

1 Answers1

2
EXEC msdb.dbo.sp_send_dbmail
   @recipients = 'xxx@yyy.com',
   @subject = 'test',
   @file_attachments = 'C:\Test\Image.gif;C:\Test\Image2.gif',
   @body=N'<p>Image Test</p><img src="Image.gif" /><p>See image there?</p>',
   @body_format = 'HTML';

Here is the exact code that I used, and it worked just fine for me.

EXEC msdb.dbo.sp_send_dbmail
   @recipients = 'xxx@wxxxx.com',
   @subject = 'test',
   @profile_name = 'global config',
   @file_attachments = 'C:\testimage.png',
   @body=N'<p>Image Test</p><img src="testimage.png" /><p>See image there?</p>',
   @body_format = 'HTML';
Dale K
  • 25,246
  • 15
  • 42
  • 71
Steve Stedman
  • 2,632
  • 3
  • 21
  • 21
  • if my @file_attachments = 'C:\logo.png' how should the – Squirrel Apr 12 '12 at 03:57
  • Sorry, it does not work. The image is not shown. Just a white box instead – Squirrel Apr 12 '12 at 04:12
  • You should just be able to map the file attachment of c:\logo.png as – Steve Stedman Apr 12 '12 at 04:18
  • I just tried it again, and it worked fine. correction, I am not using the cid: option, just specifying the image name with no path. it works great. – Steve Stedman Apr 12 '12 at 04:37
  • i still don't get that. Could it be related to the email client ? I am sending the mail to my GMAIL and i view it via the browser on gmail.com and the image does not appear after the "Image Test" line. Only in the attachment. – Squirrel Apr 12 '12 at 05:40
  • Thanks for your help Steve. I have just tried with different email client. For Outlook, it does display the image there but not gmail.com. I was testing with accessing the mail from gmail.com all along. I need a solution that can works on most client. Some of the receipient is using gmail via web, some will be using mobile phone. hopefully there will be a solution that will works if not all most of devices – Squirrel Apr 12 '12 at 06:10
  • 2
    Just using `` and the `@file_attachments` parameter does not add the required `Content-ID` header to the image attachments. This is fine for Outlook, because when it can't find the `Content-ID` header it scans the `Content-Disposition` headers for a matching filename attribute (and so displays the image inline), but every other mail client I've tried just displays the images as a file attachments to the message. We wound up using a solution that builds the message in a table and drops it in a Pickup directory for delivery via IIS6-SMTP. – AlwaysLearning Nov 07 '13 at 05:40