-
Notifications
You must be signed in to change notification settings - Fork 46
Sending Inline Images
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 = "Inline Images",
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.
The Postmark.Net client can be installed from NuGet.
For additional information about the capabilities of the Postmark API, see http://developer.postmarkapp.com/.
- Getting Started
- Version 2.0 Upgrade Guide
- Sending Email
- Searching Sent Messages
- Analyzing Sent Messages
- Processing Inbound Email
- Retrieving Message Statistics
- Handling Bounces
- Managing Suppressions
- Working with Message Streams
- Managing Your Account
- Troubleshooting Async&Await
- Version 1.x Overview
- Sending Email
- Sending Batch Emails
- Sending Attachments
- Sending Inline Images
- Using
MailMessage
- Using the Bounce API
- [Getting Send Statistics](Sending Statistics)
- Adding Custom Email Headers