3

I have a complex email template that contains many div, section and other HTML elements. The HTML template has reference to CSS(uploaded to server). I am using the below code to send HTML email via MailKit :

var message = new MimeMessage();
var bodyBuilder = new BodyBuilder();
bodyBuilder.HtmlBody = File.ReadAllText(pathToHtmlFIle);
message.Body = bodyBuilder.ToMessageBody();

client.Send(message);

But the client only receives everything in plain-text, no colors, no formatting. Is this the expected result ?

Software Dev
  • 5,368
  • 5
  • 22
  • 45
  • To answer your question, I don't think it **is** the expected result, no. However, while not familiar with MailKit too well, there are some SO answers [like this one](https://stackoverflow.com/a/42208630/3390788) which may be of help – Frank Alvaro Nov 17 '18 at 18:32
  • @ffa, i checked the post long ago. It didn't help. – Software Dev Nov 17 '18 at 18:48
  • Some additional information would help provide more clues as to what could be going wrong such as the raw MIME of the message that was sent (you can do `message.WriteTo ("file.txt")`), and, if possible, the raw message that the client received (most mail clients allow you to save the message to a file). Perhaps a screenshot of what the message looks like in the receiving client would also be useful. – jstedfast Nov 18 '18 at 12:09

2 Answers2

6

I think you need to use either inline CSS or CSS embedded in the head section. Since most webmail clients block links to external stylesheets, it is rare to see this method employed in an email.

Ole EH Dufour
  • 2,968
  • 4
  • 23
  • 48
0

After struggling a lot with this topic, I finally figure out the error was the double quotes inside the html...Use notepad++ to replace (quick launched with ctrl+f) all " for '. Holy remedy, after only receiving plain/text I finally received the text/html.

PD: Do not use bootstrap nor try to link an external source 'cause mail clients block external css providers. Use strictly style attributes for all tags.

Ramiro G.M.
  • 357
  • 4
  • 7