如何修复发送电子邮件泰语文本?

时间:2014-01-16 09:41:03

标签: email asp-classic cdo.message

我尝试通过.asp(经典)页面发送泰语电子邮件。代码在

之下
<%
response.write(GetLocale() & "<br />")
SetLocale(1054)
response.write(GetLocale())


Set Mail = CreateObject("CDO.Message")

Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="smtp.gmail.com"
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465

Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1

Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="xxx@gmail.com"
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="xxx"

Mail.Configuration.Fields.Update

Mail.Subject="ระบบแจ้งเตือนอัตโนมัติ"
Mail.From="xxx@gmail.com"
Mail.To="xxx@hotmail.com"
Mail.TextBody="สวัสดี"



Mail.Send
Set Mail = Nothing

%>

但我收到的结果电子邮件是

  

????? ???????????????????? ?????????????????????????????????????????????????? ?????????????????????? ?????????????????????????????????????????????????? ??????

任何人都知道如何解决,请帮忙吗?

修复方法(通过下面的ulluoink)

将这个鲜为人知的bit-o-goodness添加到您的页面中:

Response.CodePage = 65001
Response.CharSet = "utf-8"

更改xml:

<?xml version="1.0" encoding="UTF-8" ?>.

您还可以确保您的META标签不会出现:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

并使用此代码模式:

<%
function TestEMail(sFrom, sTo, sSubject, sBody,  sBcc)
    Set objMail = Server.CreateObject("CDO.Message")
    Set objConf = Server.CreateObject("CDO.Configuration") 
    Set objFields = objConf.Fields
    With objFields
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")  =  "mail.secureserver.net"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10 
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        .Update 
    End With

    With objMail
        Set .Configuration = objConf
        .BodyPart.Charset = "utf-8"
        .From = sFrom
        .To = sTo
        .Subject = sSubject
        .TextBody = sBody
        if sBcc <> "" then .Bcc = sBcc
        End With

    objMail.Send
    Set objFields = Nothing
    Set objConf = Nothing
    Set objMail = Nothing
End function
%>

1 个答案:

答案 0 :(得分:1)

您必须对以下内容使用utf-8编码:

  • 您的asp页面(该文件必须以utf-8编码保存)
  • 然后使用以下命令在asp中设置编码:

    Response.CodePage = 65001

    Response.CharSet =“utf-8”

  • 在邮件对象的bodypart中设置utf-8:

    Mail.BodyPart.Charset =“utf-8”

进一步看看here(关于经典asp和utf-8的hanselman)和here(cdo和utf-8的例子)