views:

1929

answers:

3

Hi All, I'm working on an email solution in SQL Server ONLY that will use Database Mail to send out HTML formatted emails. The catch is that the images in the HTML need to be embedded in the outgoing email. This wouldn't be a problem if I were using a .net app to generate & send the emails but, unfortunately, all I have is SQL Server.

Is it possible for SQL Server to embed images on its own?

A: 

You could try to encode the image as base64 and reference it directly in an img tag within the email ( <img src="data:image/png;base64[your encoded image here...] ) but i think most email clients correlate this technique with spam. I think you're better off referencing hosted images or simply attaching it to the email.

Nathan Skerl
A: 

Yes, what you need to do is include the images as attachments and then they can be referenced within the HTML.

Use the @file_attachment parameter of sp_send_dbmail

Josef
+2  A: 

You have two possibilities:

  1. (easy) Host the images somewhere, and reference them in the <img src="...">.
  2. (difficult) Encode them in Base64 and build a multipart MIME message with known content IDs, so they can be referenced in the message body via cid: URIs.

Each possibility has its downsides:

  1. Remote images may not be loaded on the modern e-mail clients for privacy.
  2. Probably rises spam score.

When the receiving clients are in your control (e.g. same organization), you might be equally fine with either way.

Tomalak