Search code examples
mailkitmimekit

Send email html body as Base64 encoded


How do I in Mimekit send an email having the html body base64 encoded?

In code I first create the entire body as a MimeEnitity including attachments using the BodyBuilder. Then I create the MimeMessage to be sent having the body.


Solution

  • The first thing you'll need to do is to locate the HTML body part.

    A quick hack might look something like this:

    var htmlBody = message.BodyParts.OfType<TextPart> (x => x.IsHtml).FirstOrDefault ();
    

    Then you'll need to set the Content-Transfer-Encoding:

    htmlBody.ContentTransferEncoding = ContentEncoding.Base64;
    

    That's it.