[英]Compiling HTML body for mail in c#
I am using the following codes for users to send me a quote to my email. 我使用以下代码向用户发送报价给我的电子邮件。
using System.Net.Mail;
MailMessage mail = new MailMessage();
mail.From = new MailAddress(Email.Text);
mail.To.Add("my yahoo email");
mail.Subject = "Requested Quote From my site";
mail.Body = "<br /><b>Primary project type:</b> " + ProjectTypeRadio.SelectedItem.Text + "<br /><b>Interested In:</b> " + InterestedCheck + "<br /><br /><br /><br /><b>PRODUCT DETAILS:</b><hr />" + Electric + HotWater + PoolHeating + SpaceHeating + "<br /> + "<br /><b>Message:</b><br /><hr /><br />" + txtMsg.Text + "<br /><br />";
SmtpClient smtp = new SmtpClient("smtp.mail.yahoo.com");
smtp.Send(mail);
Response.Redirect("Thanks.aspx");
Web.Config Web.Config中
<system.net>
<mailSettings>
<smtp>
<network host="smtp.mail.yahoo.com" port="995" userName="my yahoo email" password="Password" />
</smtp>
</mailSettings>
PROBLEM: I am recieving the mail in my yahoo account but the message is not formated instead its showing all the HTML tags ie 问题:我收到了我的雅虎帐户中的邮件,但邮件没有格式化而是显示所有HTML标签,即
Can anyone please check my code and point my mistake or guide me a solution, it will be a big favor, thanks. 任何人都可以检查我的代码并指出我的错误或指导我一个解决方案,这将是一个很大的帮助,谢谢。
You can set mail.IsBodyHTML = true
您可以设置
mail.IsBodyHTML = true
Also, depending on what you're sending you may want to use AlternateViews to send both plain text and text/html variations. 此外,根据您发送的内容,您可能希望使用AlternateViews发送纯文本和文本/ html变体。
你必须设置BodyFormat
mail.BodyFormat = System.Web.Mail.MailFormat.Html;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.