Base64 embedding of related images

In EMBEDDED PICTURES NOT DISPLAYED? BASE TAG CAN BE THE CAUSE. post I explained how to fix the problem of displaying e-mails with embedded pictures.

MailBee.NET Objects v11 now supports another method of preparing related images so that you can display them regardless of tag and avoid the necessity to save them locally on your server. With this method you can embed images directly in the HTML message body as base64-encoded “data” blocks.

// msg is a MailMessage instance
html = msg.GetHtmlWithBase64EncodedRelatedFiles();

So, if you have a message which contains some related images which are embedded into the message as inline attachments, this method will embed them directly in the message body. You don’t need these attachments any longer.

Just to avoid confusion. There are two types of embedding. An image can be embedded into the message at inline attachment (rather than be referenced by an external link) or be embedded directly in the HTML body as “data” blocks. What we’re talking about is converting inline attachments into “data” blocks.

The method above is mostly intended for parsing and viewing existing e-mails. However, if you’re building a new message and want to base64-embed inline attachments, it can also be used:

// msg is a MailMessage instance
msg.LoadBodyText(@"C:\Temp\body.html", MessageBodyType.Html, null, ImportBodyOptions.ImportRelatedFiles);
html = msg.GetHtmlWithBase64EncodedRelatedFiles();
msg.Attachments.Clear(); // Remove attachments just added, we don't need them anymore.
msg.BodyHtmlText = html;

Please note that it’s recommended to use base64 embedding only if your images are relatively small. Older browsers may have issues with displaying images larger than 32KB in size. Also, Gmail currently does not support base64 encoded images! This means you cannot send an email with base64 encoded images to Gmail users.

Base64 embedding of related images

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s