Problem with the encoding of a CDO subject

Discussion in 'ASP General' started by ioannisd, Dec 30, 2007.

  1. ioannisd

    ioannisd Guest

    Hi,

    I am sending emails though CDO (using ASP). In my mail I have Greek
    characters which are not being displayed correctly unless I do
    Server.HTMLEncode(textmsg) before submitting it to CDO (and that works
    fine!). My problem is that I cannot get the subject of the email to
    work with Greek characters.

    I guess there must a property for the encoding but I have not been
    able to find out which one it is....

    This is my ASP code....

    '===========================================

    Function sendMail(recipient, subject, msg)
    Response.Write(Recipient)
    Response.Write("<br>")
    Response.Write(subject)
    Response.Write("<br>")
    Response.Write(msg)
    Response.Write("<br>")



    Const cdoSendUsingPickup = 1
    Const cdoSendUsingPort = 2 'Must use this to use Delivery
    Notification
    Const cdoAnonymous = 0
    Const cdoBasic = 1 ' clear text
    Const cdoNTLM = 2 'NTLM
    'Delivery Status Notifications
    Const cdoDSNDefault = 0 'None
    Const cdoDSNNever = 1 'None
    Const cdoDSNFailure = 2 'Failure
    Const cdoDSNSuccess = 4 'Success
    Const cdoDSNDelay = 8 'Delay
    Const cdoDSNSuccessFailOrDelay = 14 'Success, failure or delay

    set objMsg = CreateObject("CDO.Message")
    set objConf = CreateObject("CDO.Configuration")

    Set objFlds = objConf.Fields
    With objFlds
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") =
    cdoSendUsingPort
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
    "smtp.mail.yahoo.com"
    .Item("http://schemas.microsoft.com/cdo/configuration/
    smtpserverport") = 465
    .Item("http://schemas.microsoft.com/cdo/configuration/
    smtpconnectiontimeout") = 20
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") =
    True
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusername")
    = "<MYUSERNAME>"
    .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")
    ="<MYPASSWORD>"
    .Item("http://schemas.microsoft.com/cdo/configuration/
    smtpauthenticate") = 1

    .Update
    End With

    'strBody = "This is a sample message." & vbCRLF
    'strBody = strBody & "It was sent using CDO." & vbCRLF
    strBody = msg & vbCRLF

    With objMsg
    Set .Configuration = objConf
    .To = recipient
    .From = "<MY EMAIL>"
    .Subject = subject

    .HTMLBody = "<br>THIS IS HTMLBODY: " & strBody
    .Fields.update

    .Send
    End With

    sendEmail = err.Number

    for each field in objMsg.fields
    Response.Write("<B>"&field.name&"</B> : " & field.value & "<BR>")
    next



    Response.Write("======================================<BR>")

    End Function
     
    ioannisd, Dec 30, 2007
    #1
    1. Advertising

  2. "ioannisd" <> wrote in message
    news:...
    > Hi,
    >
    > I am sending emails though CDO (using ASP). In my mail I have Greek
    > characters which are not being displayed correctly unless I do
    > Server.HTMLEncode(textmsg) before submitting it to CDO (and that works
    > fine!). My problem is that I cannot get the subject of the email to
    > work with Greek characters.
    >
    > I guess there must a property for the encoding but I have not been
    > able to find out which one it is....
    >
    > This is my ASP code....
    >
    > '===========================================
    >
    > Function sendMail(recipient, subject, msg)
    > Response.Write(Recipient)
    > Response.Write("<br>")
    > Response.Write(subject)
    > Response.Write("<br>")
    > Response.Write(msg)
    > Response.Write("<br>")
    >
    >
    >
    > Const cdoSendUsingPickup = 1
    > Const cdoSendUsingPort = 2 'Must use this to use Delivery
    > Notification
    > Const cdoAnonymous = 0
    > Const cdoBasic = 1 ' clear text
    > Const cdoNTLM = 2 'NTLM
    > 'Delivery Status Notifications
    > Const cdoDSNDefault = 0 'None
    > Const cdoDSNNever = 1 'None
    > Const cdoDSNFailure = 2 'Failure
    > Const cdoDSNSuccess = 4 'Success
    > Const cdoDSNDelay = 8 'Delay
    > Const cdoDSNSuccessFailOrDelay = 14 'Success, failure or delay
    >
    > set objMsg = CreateObject("CDO.Message")
    > set objConf = CreateObject("CDO.Configuration")
    >
    > Set objFlds = objConf.Fields
    > With objFlds
    > .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") =
    > cdoSendUsingPort
    > .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
    > "smtp.mail.yahoo.com"
    > .Item("http://schemas.microsoft.com/cdo/configuration/
    > smtpserverport") = 465
    > .Item("http://schemas.microsoft.com/cdo/configuration/
    > smtpconnectiontimeout") = 20
    > .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") =
    > True
    > .Item("http://schemas.microsoft.com/cdo/configuration/sendusername")
    > = "<MYUSERNAME>"
    > .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")
    > ="<MYPASSWORD>"
    > .Item("http://schemas.microsoft.com/cdo/configuration/
    > smtpauthenticate") = 1
    >
    > .Update
    > End With
    >
    > 'strBody = "This is a sample message." & vbCRLF
    > 'strBody = strBody & "It was sent using CDO." & vbCRLF
    > strBody = msg & vbCRLF
    >
    > With objMsg
    > Set .Configuration = objConf
    > .To = recipient
    > .From = "<MY EMAIL>"
    > .Subject = subject
    >
    > .HTMLBody = "<br>THIS IS HTMLBODY: " & strBody
    > .Fields.update
    >
    > .Send
    > End With
    >
    > sendEmail = err.Number
    >
    > for each field in objMsg.fields
    > Response.Write("<B>"&field.name&"</B> : " & field.value & "<BR>")
    > next
    >
    >
    >
    > Response.Write("======================================<BR>")
    >
    > End Function
    >


    Try adding this to your code:-

    objMsg.BodyPart.Charset = "utf-8"



    --
    Anthony Jones - MVP ASP/ASP.NET
     
    Anthony Jones, Dec 30, 2007
    #2
    1. Advertising

  3. ioannisd

    ioannisd Guest

    On Dec 31, 12:29 am, "Anthony Jones" <> wrote:
    > "ioannisd" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > Hi,

    >
    > > I am sending emails though CDO (using ASP). In my mail I have Greek
    > > characters which are not being displayed correctly unless I do
    > > Server.HTMLEncode(textmsg) before submitting it to CDO (and that works
    > > fine!). My problem is that I cannot get the subject of the email to
    > > work with Greek characters.

    >
    > > I guess there must a property for the encoding but I have not been
    > > able to find out which one it is....

    >
    > > This is my ASP code....

    >
    > > '===========================================

    >
    > > Function sendMail(recipient, subject, msg)
    > > Response.Write(Recipient)
    > > Response.Write("<br>")
    > > Response.Write(subject)
    > > Response.Write("<br>")
    > > Response.Write(msg)
    > > Response.Write("<br>")

    >
    > > Const cdoSendUsingPickup = 1
    > > Const cdoSendUsingPort = 2 'Must use this to use Delivery
    > > Notification
    > > Const cdoAnonymous = 0
    > > Const cdoBasic = 1 ' clear text
    > > Const cdoNTLM = 2 'NTLM
    > > 'Delivery Status Notifications
    > > Const cdoDSNDefault = 0 'None
    > > Const cdoDSNNever = 1 'None
    > > Const cdoDSNFailure = 2 'Failure
    > > Const cdoDSNSuccess = 4 'Success
    > > Const cdoDSNDelay = 8 'Delay
    > > Const cdoDSNSuccessFailOrDelay = 14 'Success, failure or delay

    >
    > > set objMsg = CreateObject("CDO.Message")
    > > set objConf = CreateObject("CDO.Configuration")

    >
    > > Set objFlds = objConf.Fields
    > > With objFlds
    > > .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") =
    > > cdoSendUsingPort
    > > .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
    > > "smtp.mail.yahoo.com"
    > > .Item("http://schemas.microsoft.com/cdo/configuration/
    > > smtpserverport") = 465
    > > .Item("http://schemas.microsoft.com/cdo/configuration/
    > > smtpconnectiontimeout") = 20
    > > .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") =
    > > True
    > > .Item("http://schemas.microsoft.com/cdo/configuration/sendusername")
    > > = "<MYUSERNAME>"
    > > .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")
    > > ="<MYPASSWORD>"
    > > .Item("http://schemas.microsoft.com/cdo/configuration/
    > > smtpauthenticate") = 1

    >
    > > .Update
    > > End With

    >
    > > 'strBody = "This is a sample message." & vbCRLF
    > > 'strBody = strBody & "It was sent using CDO." & vbCRLF
    > > strBody = msg & vbCRLF

    >
    > > With objMsg
    > > Set .Configuration = objConf
    > > .To = recipient
    > > .From = "<MY EMAIL>"
    > > .Subject = subject

    >
    > > .HTMLBody = "<br>THIS IS HTMLBODY: " & strBody
    > > .Fields.update

    >
    > > .Send
    > > End With

    >
    > > sendEmail = err.Number

    >
    > > for each field in objMsg.fields
    > > Response.Write("<B>"&field.name&"</B> : " & field.value & "<BR>")
    > > next

    >
    > > Response.Write("======================================<BR>")

    >
    > > End Function

    >
    > Try adding this to your code:-
    >
    > objMsg.BodyPart.Charset = "utf-8"
    >
    > --
    > Anthony Jones - MVP ASP/ASP.NET


    Fixed!
    Thanks
     
    ioannisd, Dec 31, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    2
    Views:
    960
    dave wanta
    Jul 11, 2003
  2. Hardy Wang

    Encoding.Default and Encoding.UTF8

    Hardy Wang, Jun 8, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    19,064
    Jon Skeet [C# MVP]
    Jun 9, 2004
  3. Jan-Hendrik Lendholt

    Wrong encoding in message subject

    Jan-Hendrik Lendholt, Dec 29, 2005, in forum: Java
    Replies:
    2
    Views:
    10,482
    Igor Planinc
    Dec 29, 2005
  4. Irene
    Replies:
    0
    Views:
    243
    Irene
    May 1, 2004
  5. Replies:
    0
    Views:
    319
Loading...

Share This Page