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 正文
基础教程推荐
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- WPF 模态进度窗口 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
