Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send email in richtext format to Outlook?

It works great to send emails (to Outlook) in HTML format by assigning the text/html content type string like so:

using (MailMessage message = new MailMessage())
{
  message.From = new MailAddress("[email protected]");
  message.ReplyTo = new MailAddress("[email protected]");
  message.To.Add(new MailAddress("[email protected]"));
  message.Subject = "This subject";
  message.Body = "This content is in plain text";
  message.IsBodyHtml = false;

  string bodyHtml = "<p>This is the HTML <strong>content</strong>.</p>";

  using (AlternateView altView = AlternateView.CreateAlternateViewFromString(bodyHtml,
    new ContentType(MediaTypeNames.Text.Html)))
  {
    message.AlternateViews.Add(altView);
    SmtpClient smtp = new SmtpClient(smtpAddress);
    smtp.Send(message);
  }
}

The email is correctly recognized as HTML in Outlook (2003).
But if I try rich text:

MediaTypeNames.RichText;

Outlook doesn't detect this, it falls back to plain text.
How do I send email in rich text format?

like image 709
Magnus Johansson Avatar asked Jan 21 '10 13:01

Magnus Johansson


People also ask

What is Rich Text Format in Outlook?

Rich Text Format: It's Microsoft email format which is supported by all Outlook versions and Microsoft Exchange Clients (versions 4.0 and 5.0). You can use Rich Text Format in your emails when you're sending emails within an organization that uses Microsoft Exchange.

How do I get email HTML format in Outlook?

Outlook for Windows In Outlook, select “File” > “Options“. Select “Mail” in the left pane. In the “Compose messages” section, change the “Compose messages in this format:” to “HTML“, “Rich Text“, or “Plain Text” as desired.

How do I change the format of my email in Outlook?

Go to File > Options. In the Outlook Options dialog box, select Mail. Select the Compose messages in this format drop-down arrow and choose the format you want to use as the default for new emails. Select OK.

Why is my Outlook email in plain text?

When replying, Outlook always uses the format of the original message by default. There is some sound logic behind it. If someone sent you a plain text message, it might mean that their email client doesn't support the more advanced formats.


2 Answers

The bottom line is, you can't do this easily using System.Net.Mail.

The rich text in Outlook is sent as a winmail.dat file in the SMTP world (outside of Exchange).

The winmail.dat file is a TNEF message. So, you would need to create your richtext inside of the winmail.dat file (formatted to TNEF rules).

However, that's not all. Outlook uses a special version of compressed RTF, so, you would also need to compress your RTF down, before it's added to the winmail.dat file.

The bottom line, is this is difficult to do, and unless the client really, really needs this functionality, I would rethink it.

This isn't something you can do with a few lines of code in .NET.

like image 195
dave wanta Avatar answered Sep 28 '22 01:09

dave wanta


You can also achieve this by adding another alternate view before your calendar view as below:

var body = AlternateView.CreateAlternateViewFromString(bodyHtml, new System.Net.Mime.ContentType("text/html"));
mailMessage.AlternateViews.Add(body);
like image 25
Sayeed Choudhury Avatar answered Sep 28 '22 00:09

Sayeed Choudhury