Skip to content

Sending Inline Images

Andrew Theken edited this page Dec 11, 2014 · 6 revisions

Sending inline images is simple with the Postmark library and is fully supported by the API.

In this example we want to send the bacon.jpg file, inline with our message:

var message = new PostmarkMessage
{
    From = "someone@example.com",
    To = "recipient@example.com",
    Subject = "Inline Images",
    HtmlBody = "<html><body><img src=\"cid:bacon.jpg\"></body></html>"
};

message.AddAttachment(@"c:\temp\bacon.jpg", "image/jpeg", "bacon.jpg");

var client = new PostmarkClient("SERVER_TOKEN");
var responses = client.SendMessage(message);

To do this, we took two steps:

  1. Add a src attribute to our image with the cid: prefix to the file name we want to use for the attachement.
  2. Include the file name when adding the attachment to the message "bacon.jpg"

Technically, the "file name" above is the "Content ID" associated with the attachment, but using the file name is recommended.

Clone this wiki locally