在 C# 中为邮件编译 HTML 正文

1

本文介绍了在 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 正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14