[英]How to format Asp.net SMTP Email with HTML?
I was doing an SMTP email that will send the order details to the customer email after the purchase.我正在做一个 SMTP 电子邮件,它将在购买后将订单详细信息发送到客户电子邮件。 I had successfully sent it to the customer but the format is a little weird.
我已成功将其发送给客户,但格式有点奇怪。
Below is the output it sends to the customer email.以下是它发送到客户电子邮件的输出。
Your order is successful!
------------------------------------------------
Order ID : Order20465230820207quiw< br />Order Date : 8/30/2020< br />Send To : 81,JALAN KENARI MERAH 8
<br /> Kedah< br /> 05200< br />Grand Total : 499< br />< br />< br />Thank You for purchasing with us!
But it expects it to format like this :但它希望它的格式如下:
Your order is successful!
------------------------------------------------
Order ID : Order20465230820207quiw
Order Date : 8/30/2020
Send To : 81,JALAN KENARI MERAH 8
Grand Total : 499
Thank You for purchasing with us!
Here is the code:这是代码:
lblmail.Text = "Your order is succesful! <br />" +
"------------------------------------------------ <br />" +
"Order ID : " + Session["OrderID"].ToString() + "< br />" +
"Order Date : " + Session["orderDate"].ToString() + "< br />" +
"Send To : " + Session["address"].ToString() + "< br />" +
" " + Session["state"].ToString() + "< br />" +
" " + Session["zipcode"].ToString() + "< br />" +
"Grand Total : " + Session["GrandTotal"].ToString() + "< br />" +
"< br />< br />Thank You for purchasing with us!" ;
Do note that I had enabled the HTML is the email body with this code:请注意,我已启用 HTML 是带有以下代码的电子邮件正文:
MailMessage mm = new MailMessage();
mm.IsBodyHtml = true;
What is the problem here?这里有什么问题? The code seems to be fine but the output is not what I expected.
代码似乎很好,但输出不是我所期望的。
确保您的 HTML 标签编写正确“< br />”删除空格,这样您就可以确保服务器不会将其作为文本发送。
< br /> To this <br/>
You need to add HTML insted of normal text您需要添加 HTML insted 的普通文本
Code代码
var htmlContent ="<!DOCTYPE html>
<html>
<body>
<h3><p>Your order is successful!</p></h3>
<p>----------------------------------</p>
<p>Order ID : Order20465230820207quiw</p>
<p>Order Date : 8/30/2020</p>
<p>Send To : 81,JALAN KENARI MERAH 8</p>
<p>Grand Total : 499</p>
<p>Thank You for purchasing with us!</p>
</body>
</html>";
using (MailMessage mm = new MailMessage())
{
mm.Body = htmlContent;
mm.IsBodyHtml = true;
}
It's working fine with your mail functionality您的邮件功能运行良好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.