开发者

Sending mails in different languages using ASP and CDOSYS

I want to send an email using arabic text as subject line.

The code piece converts the special characters into arabic tex开发者_如何学JAVAt properly for message body but fails to do so for message subject.

I would like to know what I am missing ?

      Set objCDOSYS = Server.CreateObject("CDO.Message")
      Set objCDOConf = CreateObject("CDO.Configuration")
      Set objCDOFields = objCDOConf.Fields

      objCDOFields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
      objCDOFields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "127.0.0.1"
      objCDOFields.Update

      Set objCDOSYS.Configuration = objCDOConf
      objCDOSYS.MimeFormatted=True 
      objCDOSYS.BodyPart.Charset = "Windows-1256"

      objCDOSYS.From = Trim(Request.Form("frmSender"))
      objCDOSYS.To = Trim(Request.Form("frmRecipient"))

      objCDOSYS.Subject =Request.Form("frmSubject")
      objCDOSYS.HTMLBody = Trim(Request.Form("frmMessage")) 

      objCDOSYS.HTMLBodyPart.charset = "Windows-1256"
      objCDOSYS.Fields.update

      objCDOSYS.Send
      Set objCDOFields = Nothing
      Set objCDOConf = Nothing
      Set objCDOSYS = Nothing


Changing to the UTF-8 charset is worth a stab:-

objCDOSYS.HTMLBodyPart.charset = "UTF-8"

I think that will result in the kind of encoding Jirapong was trying but CDOSYS will do it for you. Unfortunately I know that it doesn't work for display names in the email addresses.


You may need to use '=?UTF-8?B?' in front of subject and the Arabic base64 encoded string.

objCDOSYS.Subject = "=?UTF-8?B?" + Base64Encode(Request.Form("frmSubject"))

The Base64Encode function can find at - http://nolovelust.com/post/classic-asp-base64-encoder-decoder.aspx

Note: I did try this myself yet. so not 100% sure.


For me the combination of these 4 items worked:

session.codepage=65001
Response.Charset = "utf-8" 
objMessage.HTMLBodyPart.Charset = "utf-8"
objMessage.BodyPart.Charset = "utf-8"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜