This is my code :
MailMessage mail = new MailMessage();
mail.From = new MailAddress(emailFrom);
mail.To.Add(new MailAddress(emailTo));
mail.IsBodyHtml = true;
mail.Subject = subject;
mail.Body = body.ToString();
System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(RemoteServerCertificateValidationCallback);
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(body, Encoding.UTF8, "text/html");
mail.AlternateViews.Add(htmlView);
SmtpClient smtp = new SmtpClient();
smtp.Host = "mail.alpc.ir";
smtp.Port = 25;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(emailFrom, emailFromPassword);
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(mail);
Email is sent successfully, but it's sent as plain text.
Received email :
p{margin-top: 0;margin-bottom: 0.5rem;}:root{--w1:600px;}:root{--d2:0.5rem;}:root{--fs:12px}@font-face {font-family: iransans;font-style: normal;font-weight: normal;src: url('https://sadidgostaran.ir/Content/IRANSansWeb.woff2') format('woff2');}@media only screen and (max-width:630px){:root{--w1:100%;}}@media only screen and (max-width:420px){:root{--fs:10px}.table-responsive{display: block;width: 100%;overflow-x: auto;-webkit-overflow-scrolling: touch;}}
گیرنده گرامیwerqwefsdvfasdf asfweqfwqr werwqreqwf werwqrqwefswadf qwerewrwerqwefsdvfasdf asfweqfwqr werwqreqwf werwqrqwefswadf qwerewrwerqwefsdvfasdf asfweqfwqr werwqreqwf werwqrqwefswadf qwerewrwerqwefsdvfasdf asfweqfwqr werwqreqwf werwqrqwefswadf qwerewrwerqwefsdvfasdf asfweqfwqr werwqreqwf werwqrqwefswadf qwerewrwerqwefsdvfasdf asfweqfwqr werwqreqwf werwqrqwefswadf qwerewrwerqwefsdvfasdf asfweqfwqr werwqreqwf werwqrqwefswadf qwerewr
ما را در شبکه های اجتماعی دنبال کنید سدید گستران در گوگلمحمد مهدی نعمتیسمت شخصسدید گستران امین 021-54942 - 09123456789 [email protected] www.sadidgostaran.ir میدان ولیعصر - ساختمان تجاری ایرانیان - طبقه 4 - واحد 5
ishtmlthat you assign to themail.IsBodyHtmlproperty?ishtmlonmail.IsBodyHtml = ishtmlis it have the correct value? that being said, even if you tell the client its html some may ignore it and show it as plain text for security. also, make sure to use inlined css and avoid custom fonts for maximum compatibility.AlternateViewto avoid giving user gibberish html in case their client is refusing html. most of your problem will be on the client instead of the c# smtp API, fyi.trueit does not work. As written, it's not possible to see whether it's true or not. And honestly, other programmers aren't going to trust you ;)