How to send HTML message via Mimekit/Mailkit
Solution 1:
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);
Solution 2:
MimeKit Documentation - Creating Messages
var message = new MimeMessage();
message.Body = new TextPart ("html") { Text = "<b>Test Message</b>" };
"A TextPart is a leaf-node MIME part with a text media-type. The first argument to the TextPart constructor specifies the media-subtype: plain, html, enriched, rtf, and xml."
Solution 3:
One other option here if you want to be strict;
msg.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = "<b>html content</b>" };
Solution 4:
var bodyBuilder = new BodyBuilder();
bodyBuilder.HtmlBody = body;
bodyBuilder.TextBody = "-";
message.Body = bodyBuilder.ToMessageBody();
In some mail ISP, you should always set bodyBuilder.TextBody by value.