某些字符在HTML电子邮件VB中不起作用

某些字符在HTML电子邮件VB中不起作用,html,vb.net,Html,Vb.net,我使用一个应用程序生成HTML电子邮件并发送给客户。这适用于某些字符,即()&*%$#@!~=+/-?'不起作用。下面是我使用的代码。请建议我如何在我的HTML电子邮件中允许这些特殊字符 Sub subHtmlEmail(ByVal strAddresseeEmail As String, ByVal strGroup As String) Try Dim strTo, strFrom, strBody, strSubject, strBcc As String

我使用一个应用程序生成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
Sub-subHtmlEmail(ByVal-strAddresseeEmail作为字符串,ByVal-strGroup作为字符串)
尝试
Dim strTo、strFrom、strBody、strSubject、strBcc As String
Dim boolHtml As Boolean=True'将正文内容设置为纯文本(false)或HTML(True)
strFrom=”sales@mycompany.com"
strTo=电子邮件';分隔电子邮件
strBcc=“”;分隔电子邮件
strSubject=txtEmailSubject.Text
strBody=“”
strBody=strBody&“
strBody&=“

” strBody&=“亲爱的”&clsGroupCustomers.RetrieveAddressee(strAddresseeEmail,strGroup)&“,

” 将strLines设置为String()=txtBody.Text.Split(新的[Char](){CChar(vbCrLf)}) 将每条strLine作为strLine中的字符串 strBody&=strLine&“
” 下一个 strBody&=“

” 将strFooterLines设置为String()=txtFooter.Text.Split(新的[Char](){CChar(vbCrLf)}) 对于每个strFooterLine,作为strFooterLines中的字符串 strBody&=strFooterLine&“
” 下一个 HTMLView=AlternateView.createAlternateView-FromString(strBody,Nothing,“text/html”) strBody&=“” 子电子邮件(strFrom、strTo、strBcc、strSubject、strBody、boolHtml、strAddresseeEmail) 特例 游标=游标。默认值 MsgBox(“您的应用程序在尝试创建电子邮件时出错。”&Chr(13)&Chr(13)&Description:”&ex.Message&Chr(13)&Chr(13)&Chr(13)&Please.contact您的系统管理员。”,MsgBoxStyle.Critical,“应用程序错误”) 出口接头 结束尝试 端接头
在HTML中,这些字符应进行编码。例如:&(与符号)应作为
&


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

谢谢。我刚刚遇到System.Web.HttpUtility.HtmlEncode(myStringValue),它也可以工作。:)