我是一个生成并向客户发送HTML电子邮件的应用程序。这适用于一些字符即()& *%$#@! 〜; _ = + / - ? '不起作用。以下是我使用的代码。请建议我如何在HTML电子邮件中允许这些特殊字符。
Sub subHtmlEmail(ByVal strAddresseeEmail As String, ByVal strGroup As String)
Try
Dim strTo, strFrom, strBody, strSubject, strBcc As String
Dim boolHtml As Boolean = True ' set the body content to plain text(false) or HTML(true)
strFrom = "sales@mycompany.com"
strTo = strAddresseeEmail ' ; Separates emails
strBcc = "" ' ; Separates emails
strSubject = txtEmailSubject.Text
strBody = "<html><head></head><body>"
strBody = strBody & "<img src=cid:Logo>"
strBody &= "<br><br>"
strBody &= "Dear " & clsGroupCustomers.RetrieveAddressee(strAddresseeEmail, strGroup) & ",<br><br>"
Dim strLines As String() = txtBody.Text.Split(New [Char]() {CChar(vbCrLf)})
For Each strLine As String In strLines
strBody &= strLine & "<br>"
Next
strBody &= "<br><br>"
Dim strFooterLines As String() = txtFooter.Text.Split(New [Char]() {CChar(vbCrLf)})
For Each strFooterLine As String In strFooterLines
strBody &= strFooterLine & "<br>"
Next
HTMLView = AlternateView.CreateAlternateViewFromString(strBody, Nothing, "text/html")
strBody &= "</body></html>"
subEmail(strFrom, strTo, strBcc, strSubject, strBody, boolHtml, strAddresseeEmail)
Catch ex As Exception
Cursor = Cursors.Default
MsgBox("An error has occurred in your application while attempting to create the email." & Chr(13) & Chr(13) & "Description: " & ex.Message & Chr(13) & Chr(13) & "Please contact your System Administrator.", MsgBoxStyle.Critical, "Application Error")
Exit Sub
End Try
End Sub
答案 0 :(得分:1)
在HTML中,这些字符应该被编码。例如:&amp; (&符号)应以&
在.NET中,您可以调用HttpContext.Current.Server.HtmlEncode(myStringValue)
自动为您执行此操作。