How to send richtext email in Outlook?

It works great to send emails (in Outlook) in HTML format, assigning a string like text / html like this:

using (MailMessage message = new MailMessage()) { message.From = new MailAddress(" --@---.com "); message.ReplyTo = new MailAddress(" --@---.com "); message.To.Add(new MailAddress(" ---@---.com ")); 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); } } 

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

 MediaTypeNames.RichText; 

Outlook does not detect this; it returns to plain text.
How to send a message in text format?

+6
c # email outlook richtext
source share
3 answers

On the bottom line, you cannot easily do this using System.Net.Mail.

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 need to create your rich text inside the winmail.dat file (formatted to TNEF rules).

However, this is not all. Outlook uses a special version of compressed RTF, so you also need to compress RTF before it is added to the winmail.dat file.

The bottom line is that it is difficult to do, and if the client really needs this function, I would rethink it.

This is not something you can do with multiple lines of code in .NET.

+9
source share

You can also achieve this by adding another alternative view before the calendar view, as shown below:

 var body = AlternateView.CreateAlternateViewFromString(bodyHtml, new System.Net.Mime.ContentType("text/html")); mailMessage.AlternateViews.Add(body); 
+1
source share

It worked for me ..

 public void sendUsersMail(string recipientMailId, string ccMailList, string body, string subject) { try { MailMessage Msg = new MailMessage(); Msg.From = new MailAddress(" norepl@xyz.com ", "Tracker Tool"); Msg.To.Add(recipientMailId); if (ccMailList != "") Msg.CC.Add(ccMailList); Msg.Subject = subject; var AltBody = AlternateView.CreateAlternateViewFromString(body, new System.Net.Mime.ContentType("text/html")); Msg.AlternateViews.Add(AltBody); Msg.IsBodyHtml = true; SmtpClient smtp = new SmtpClient("mail.xyz.com"); smtp.Send(Msg); smtp.Dispose(); } catch (Exception ex) { } } 
0
source share

All Articles