vbscriptcharacter-encodingcdo.message

encoding problem for SUBJECT of email using CDO


Using vbscript (asp) with CDO I have problem with encoding in SUBJECT of email. I have used two solutions for BODY part of email and both works but non of them works for SUBJECT part.

First solution: Endcoding characters of email BODY using chrw (not working for subject):

for x=1567 to 1785
encoded="&#" & x & ";"
Body= Replace(Body, chrw(x), encoded, 1, -1, 1)
next

Second solution: setting HTMLBodyPart encoding:

objMessage.HTMLBodyPart.Charset = "utf-8"

is there something similar for SUBJECT part of email (e.g. objMessage.SubjectPart.Charset)?


Solution

  • Try:

    objMessage.TextBodyPart.Charset = "utf-8"
    

    or simply:

    objMessage.BodyPart.Charset = "utf-8"
    

    It has been documented elsewhere that modifying the Charset of the TextBodyPart also impacts (the plain/text) Subject.

    Hope this helps.