How to send HTML message via Mimekit/Mailkit

astropringles picture astropringles · Dec 15, 2016 · Viewed 29.4k times · Source
BodyBuilder bodyBuilder = new BodyBuilder();
messageContent.Body = "<b>This is a test mail</b>";
bodyBuilder.HtmlBody = messageContent.Body;

I tried to embed my body to a bodybuilder but when I received the email, it returned an empty body. I have an exception that would throw an argument if the body is empty..

Answer

jstedfast picture jstedfast · Dec 15, 2016

Using a BodyBuilder like you are doing is probably the easiest way.

var bodyBuilder = new BodyBuilder ();
bodyBuilder.HtmlBody = "<b>This is some html text</b>";
bodyBuilder.TextBody = "This is some plain text";

message.Body = bodyBuilder.ToMessageBody ();

client.Send (message);