System.Net.Mail:显示"nbsp" (字符实体)而不是空格 [英] System.Net.Mail: Displays  "nbsp" (character entity) instead of a space
问题描述
我正在使用System.Net.Mail从ASP.Net程序发送电子邮件.我将在每个句点后插入2个'& nbsp'.它可以在我的测试环境中正常工作,但是发送到gmail帐户的实际电子邮件显示2个 "而不是2个空格.
我的代码如下所示:
Hi,
I am using System.Net.Mail to send an email from a ASP.Net program. I am inserting 2 '' ''s after each period in my text. It works as it is supposed to in my testing environment, but the actual email being sent to a gmail account shows 2 '' ''s instead of 2 spaces.
My Code looks like this:
strBody = "Forms Accepted</p></td></tr>" & _
"<tr><td>Your forms have been accepted." & " " & " " & "Please log in to your account " & _
"<a style='color:#7ABB00' href='" & url & "'>here</a> " & _
"to complete your audit. "
With objEmail
.From = New MailAddress(pstrSystemEmailAddress)
.Body = strBody
.IsBodyHtml = True
Dim content As AlternateView
Email = SetImage(strBody, Nothing, "text/html", content)
.BodyEncoding = Encoding.UTF8
.Bcc.Add("testing@gmail.com")
.Priority = MailPriority.Normal
End With
电子邮件(gmail)中的结果如下所示:
您的表格已被接受.& nbsp& nbsp请在此处登录到您的帐户以完成审核.
代码中是否缺少任何设置,还是应该使用其他设置?
在此先感谢.
And the result in the email (gmail) looks like this:
Your forms have been accepted.  Please log in to your account here to complete your audit.
Is there any setting missing from my code, or should I use something different?
Thanks in advance.
推荐答案
我看到的第一个问题是HTML字符实体的语法错误:最后遗漏了``;''.现在,如果需要显示实体的HTML源(例如,在HTML代码示例中),则还需要转义&".像这样:
First problem I can see is the wrong syntax of HTML character entity: you miss '';'' at the end. Now, if you need to show the HTML source of the entity (for example, in HTML code sample), you also need to escape ''&''. Like this:
<p>
If you want to use HTML entity in code, use will be rendered as a non-breakable space
</p>
<p>
If you want to show the HTML source code in HTML, use &nbsp; will be rendered as
</p>
你有主意吗?而且,当然,要在此页面上显示它,我必须加倍跳过&"号. :-)
Are you getting the idea? And, of course, to show it on this page, I had to double escape the ampersand. :-)
将主体编码切换为ASCII而不是UFT8
Switch the body encoding to ASCII instead of UFT8
这篇关于System.Net.Mail:显示"nbsp" (字符实体)而不是空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!