Compiling HTML body for mail in c#(在 C# 中为邮件编译 HTML 正文)
问题描述
我正在使用以下代码让用户向我的电子邮件发送报价.
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
<system.net>
<mailSettings>
<smtp>
<network host="smtp.mail.yahoo.com" port="995" userName="my yahoo email" password="Password" />
</smtp>
</mailSettings>
问题:我正在我的雅虎帐户中接收邮件,但邮件未格式化,而是显示所有 HTML 标签,即
PROBLEM:
I am recieving the mail in my yahoo account but the message is not formated instead its showing all the HTML tags i.e.
谁能检查我的代码并指出我的错误或指导我一个解决方案,这将是一个很大的帮助,谢谢.
Can anyone please check my code and point my mistake or guide me a solution, it will be a big favor, thanks.
推荐答案
可以设置mail.IsBodyHTML = true
此外,根据您发送的内容,您可能希望使用 AlternateViews 发送纯文本和 text/html 变体.
Also, depending on what you're sending you may want to use AlternateViews to send both plain text and text/html variations.
这篇关于在 C# 中为邮件编译 HTML 正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C# 中为邮件编译 HTML 正文


基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01