1

我正在通过 VB 应用程序发送电子邮件。以下字符在某些电子邮件应用程序上正确显示,但在其他应用程序上,我得到了一个奇怪的替换(见附图)。我怎样才能使这些字符始终正确显示?

字符集:()&*%$#@! 〜; _ = + / - ?

信息:18cm – 22cm 宽;脂肪O

结果 :在此处输入图像描述

无论使用哪一个字符,结果始终与所附图像相同。无法正确显示的应用程序是 Outlook < 2013。

这是VB代码:

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@humeat.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)
        'subEmail(strFrom, strTo, strBcc, strSubject, System.Web.HttpUtility.HtmlEncode(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

'Send the email
Sub subEmail(ByVal strFrom, ByVal strTo, ByVal strBcc, ByVal strSubject, ByVal strBody, ByVal bolHtml, ByVal strAddresseeEmail)
    Try
        'Dim strMailServer As String = "smtp.dsl.telkomsa.net"
        Dim strMailServer As String = "smtp.insightsa.net"
        'Dim strMailServer As String = "smtp.humeat.com"
        'Dim strMailServer As String = "mail.humeat.com"

        Dim intCount As Integer
        Dim objAttachment As Attachment

        Dim objMail As New MailMessage()
        objMail.From = New MailAddress(strFrom)
        Dim i As Integer
        Dim arrArray As Array

        arrArray = Split(strTo, ";")
        For i = 0 To arrArray.Length - 1
            objMail.To.Add(arrArray(i))
        Next

        arrArray = Split(strBcc, ";")
        For i = 0 To arrArray.Length - 1
            If Not arrArray(i) = "" Then objMail.Bcc.Add(arrArray(i))
        Next

        For intCount = 0 To lstAttachments.Items.Count - 1
            objAttachment = New Attachment(lstAttachments.Items(intCount).ToString)
            objMail.Attachments.Add(objAttachment)
        Next


        ' [TW 20110309]
        ' Create the LinkedResource (embedded image)
        Dim logo As New LinkedResource("C:\humeat.bmp")
        logo.ContentId = "Logo"

        ' [TW 20110309]
        ' Add the LinkedResource to the appropriate view
        HTMLView.LinkedResources.Add(logo)

        ' [TW 20110309]
        ' Add the views
        objMail.AlternateViews.Add(PlainView)
        objMail.AlternateViews.Add(HTMLView)

        objMail.Subject = strSubject
        objMail.Body = strBody
        objMail.IsBodyHtml = bolHtml
        Dim smtp As New SmtpClient(strMailServer)
        smtp.Port = "587" ' This is not the default port of 25 but a special smtp port because they use Mweb.  HC. 2-8-2011


        smtp.Credentials = New System.Net.NetworkCredential("humeat@insightsa.net", "123Four56")
        smtp.Send(objMail)

    Catch ex As Exception
        Cursor = Cursors.Default
        'MsgBox("An error has occurred in your application while attempting to send the email to " & strTo & "." & Chr(13) & Chr(13) & "Description: " & ex.Message & Chr(13) & Chr(13) & "Please contact your System Administrator.", MsgBoxStyle.Critical, "Application Error")
        lstEmailsNotSent.Items.Add(clsGroupCustomers.RetrieveAddressee(strAddresseeEmail, cboEmailGroup.Text) & " (" & strTo & ") - " & ex.Message)
        Exit Sub
    End Try
End Sub
4

1 回答 1

2
于 2013-08-20T11:35:42.197 回答