Sending a mail as both HTML and Plain Text in .net

后端 未结 6 1303
暖寄归人
暖寄归人 2020-12-24 05:12

I\'m sending mail from my C# Application, using the SmtpClient. Works great, but I have to decide if I want to send the mail as Plain Text or HTML. I wonder, is there a way

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-24 05:50

    On top of using AlternateViews views to add both the html and the plain text view, make sure you are not also setting the body of the Mail Message object.

    // do not do this: 
    var msg = new MailMessage(model.From, model.To);
    msg.Body = compiledHtml;  
    

    As it will make your email contain the html content in both views, overriding the alternative views.

提交回复
热议问题