Search code examples
emailutf-8asp-classiccdo.messageiis-8.5

Why when I'm sending emails with CDO in Classic ASP I get ñ instead of ñ?


I'm having problems sending email in Classic ASP with CDO in IIS 8.5 and Windows 8.1, the problem happens with latin characters, like ñ áéíóúü etc. For Example if I put the ñ in the subject and/or in the body I get ñ.

These is my code:

Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields

With Fields
 .Item("http://schemas.microsoft.com/cdo/configuration/sendusing")      = 2 
 .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")     = "smtp.gmail.com"
 .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
 .Item("http://schemas.microsoft.com/cdo/configuration/sendusername")   = "[email protected]"
 .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")   = "the-pwd-123"
 .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl")     = true
 .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")   = 1

 .Update
End With

Set objMessage = Server.CreateObject("CDO.Message")

Set objMessage.Configuration = objConfig

With objMessage
 .BodyPart.Charset = "utf-8"
 '.BodyPart.Charset = "unicode-1-1-utf-8"
 .To       = "<[email protected]>"
 .From     = "<[email protected]>"
 .Subject  = "Envio de contraseña"
 .TextBody = "This email has a ñ to see how it looks when sending email through CDO"
 .Send
End With

The configuration of the email is UTF8, then where is the problem?, How can I solve this?


Solution

  • First thing, try adding this to the top of your page

    <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>.

    Also, as your ñ is hardcoded, save the file with UTF-8 encoding. If you open it in Notepad (or just about any editor other than VS) and select Save As you should see an encoding dropdown in the dialogue box which appears.

    See this for further information. http://www.hanselman.com/blog/InternationalizationAndClassicASP.aspx