How to send email in richtext format to Outlook?

 ̄綄美尐妖づ 提交于 2019-11-30 20:39:31

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.

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);

This 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)
        { 
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!