I have an ASP.Net/MVC application and I'm trying to send HTML emails. I do this by reading in the HTML file with tokens and then replacing the tokens. This part is beautiful and generates the HTML that I want, but when I send an email, what I get looks like
<style type=3D"text/css">= =0D=0A.styleTitles=0D=0A{=0D=0Afont-weight:=bold;=0D=0A}=0D=0A .style1=0D=0A {=0D=0A
and should look like
<style type="text/css"> .styleTitles { font-weight: bold; } .style1 { height: 15px; }
I looked on the Internet and I cannot find the correct syntax for sending a message. I saw some solutions, but no one works.
My current test code is
SmtpClient smtpclient = new SmtpClient(); MailMessage message = new MailMessage(); MailAddress SendFrom = new MailAddress(" xxxx@abc.com "); MailAddress SendTo = new MailAddress(" zzzz@gmail.com "); MailMessage MyMessage = new MailMessage(SendFrom, SendTo); var plainView = AlternateView.CreateAlternateViewFromString(msgBody,null,"text/html"); plainView.TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit; MyMessage.AlternateViews.Add(plainView); MyMessage.IsBodyHtml = true; MyMessage.Subject = subjectLine; MyMessage.Body = msgBody; smtpclient.Send(MyMessage);
Any suggestions?
source share