Skip to content

Sending Inline Images

JP Toto edited this page Aug 12, 2013 · 6 revisions

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

PostmarkMessage message = new PostmarkMessage
{
    From = "[email protected]",
    To = "[email protected]",
    Subject = "postmark-dotnet testing ssl api 4",
    TextBody = "Hello",
    HtmlBody = "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-1\"></head><body text=\"#000000\" bgcolor=\"#FFFFFF\">test<br><img alt=\"bacon\" src=\"cid:bacon001.jpg\" width=\"600\" height=\"442\"><br></body></html>",
    Headers = new NameValueCollection { { "CUSTOM-HEADER", "value" } },
    Tag = "Inline"
};

message.AddAttachment(@"c:\temp\bacon.jpg", "image/jpeg", "bacon001.jpg");
PostmarkClient client = new PostmarkClient("YOUR_API_KEY");
var responses = client.SendMessage(message);

In this example we want to send the bacon.jpg file inline with our messages. To do this, we add an html body to our Postmark message and embed CID (contend ID) in the places where our image sources normally would go. Then when adding the image attachment, use the extra string method to add the file along with the exact file name specified in the CID. This causes Postmark to embed the image where the CID tag is placed.

If you use an image more than once in your email (spaces, etc), you only need to add the attachment once and specify the same CID in each place the image is required. Postmark will handle the embedding.

Clone this wiki locally