0

我是一个生成 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
4

1 回答 1

1

在 HTML 中,这些字符应该被编码。例如:&(和号)应该发出为&amp;

在 .NET 中,您可以调用HttpContext.Current.Server.HtmlEncode(myStringValue)自动为您执行此操作。

于 2013-08-19T06:55:31.073 回答