views:

39

answers:

2

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

The code piece converts the special characters into arabic text 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
A: 

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.

Jirapong
Thanks for the response, I checked it but its not working. You can try it out over here http://www.franchiseforindia.com/EmailUniCode.asp
Sandhurst
@Sandhurst: There is a missing `+ "?="` from the end of the code however there is a bigger problem. We can't just pass the unicode subject string to the Base64Encode function it would first need to be converted to UTF-8.
AnthonyWJones
Thanks Anthony, You're right. It must be UTF-8.
Jirapong
A: 

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.

AnthonyWJones
I have put everything you guys told me to but still no luck.
Sandhurst