【发布时间】:2017-10-29 11:00:11
【问题描述】:
我正在尝试发送邮件。在正文部分,当我使用 html 格式时,它按原样呈现。实际上,它存储在一个 xml 文件中,所以我如何发送该 xml 格式,以便当有人收到邮件时将以正确的格式显示。
网络服务代码
public Thankyou()
{
//Uncomment the following line if using designed components
//InitializeComponent();
MailMessage o = new MailMessage("esh_p07@hotmail.com", "esh07@gmail.com", "Event Inquiry", @"< html >
< head >< title >[#text:@@hotelname#] Event Inquiry Form</title></head>
< body >
< h1 style = ""font - family:Verdana, Arial, Helvetica, sans - serif; font - weight:normal; font - size:14px; "" > You have received an email via the < b >[Culver Hotel </ b > Event Inquiry form.</ h1 >
< h2 style = ""font - family:Verdana, Arial, Helvetica, sans - serif; font - weight:normal; font - size:12px; "" >
< b > From: </ b >[#text:contact_name#] <a href=""mailto:[#text:contact_email#]"" >[#text:contact_email#]</a><br>
< b > Phone: </ b > [#text:contact_phone#]<br>
< b > Requested Date: </ b > [#text:rfp_requestmonth#] [#text:rfp_requestdate#],[#text:rfp_requestyear#]<br>
< b > Requested Time: </ b > [#text:requested_time#]<br>
< b > Number of Guests: </ b > [#text:number_guests#]<br>
< b > Comments: </ b >< br > [#text:contact_comments#]
</ h2 >
</ body >
</ html >");
NetworkCredential netCred = new NetworkCredential("user@example.com", "pAssw0rd");
SmtpClient smtpobj = new SmtpClient("wm.ebservices.com", 38);
smtpobj.EnableSsl = false;
smtpobj.Credentials = netCred;
smtpobj.Send(o);
}
这是以 xml 格式存储的正文格式,我希望当有人收到邮件时,它会以正确的格式显示,目前我正在接收带有 html 标记的消息
xml代码
<html>
<head><title>[#text:@@hotelname#] Event Inquiry Form</title></head>
<body>
<h1 style="font-family:Verdana, Arial, Helvetica, sans-serif; font-weight:normal; font-size:14px;">You have received an email via the <b>[Culver Hotel</b> Event Inquiry form.</h1>
<h2 style="font-family:Verdana, Arial, Helvetica, sans-serif; font-weight:normal; font-size:12px;">
<b>From: </b>[#text:contact_name#] <a href="mailto:[#text:contact_email#]" >[#text:contact_email#]</a><br>
<b>Phone: </b> [#text:contact_phone#]<br>
<b>Requested Date: </b> [#text:rfp_requestmonth#] [#text:rfp_requestdate#],[#text:rfp_requestyear#]<br>
<b>Requested Time: </b> [#text:requested_time#]<br>
<b>Number of Guests: </b> [#text:number_guests#]<br>
<b>Comments: </b><br> [#text:contact_comments#]
</h2>
</body>
</html>
【问题讨论】:
-
您实际上是指 XML 还是您真的是在说 XHTML(或 HTML 5 plus XML,有时称为 XHTML5)?无论哪种方式,您可能都不想将其作为电子邮件的男孩发送,您应该从表单中提取数据以构建电子邮件并发送。
-
实际上在此应用程序中,存储的数据以我在 xml 部分中显示的格式发送,但它在邮件中使用我不想要的所有 html 标签呈现,如何实现跨度>
-
尝试其他响应,它可能会满足您的需求。我通常不使用 SOAP,所以我不能确定它是否正确。另外,我已经编辑了这个 Q 和你的另一个,以删除你不想要的东西。我希望这些修改很快就会获得批准。
-
您可能有需要编码的特殊字符。使用 System.Net.WebUtility.HtmlDecode() 和/或 System.Net.WebUtility.HtmlEncode();见维基:google.com/…
标签: c# html asp.net xml web-services