We help IT Professionals succeed at work.
Get Started

How to send utf-8 email using Classic ASP

4,808 Views
Last Modified: 2012-05-06
I am having difficulty sending a message using Classic ASP and a mail component. I have created a test program (below) which uses one of several available email components. The result of all of them is the unicode text is displayed as ????.

The program below is currently on the server http://www.wow-imports.com/WBMailTest.asp. It only sends email to me for the test.

What am I doing wrong? How do I get at least ONE of these components to send out my test (so that I can then go back to my real program and get that to work)?

Thank you.
<html>
 
<head>
<%@Language=VBScript Codepage=65001%>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta content="en-us" http-equiv="Content-Language">
<title>Mail Test</title>
</head>
 
<body>
 
<% 
 
strFromName="Lev Seltzer"
strFromEmail="lev@seltzer.co.il"
strToName="Test Recipient"
strToEmail="lev.seltzer@gmail.com"
strLetter="HI<br>éÜÕÝ"
strContactFormSubject="WEBuilder Test"
strMailServer="LocalHost"
strMailComponent="JMAIL"
 
 
select case strMailComponent
case "SMTPsvg"
	Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
	Mailer.FromName   = strFromName
	Mailer.FromAddress= strFromEmail
	Mailer.AddRecipient strToName,strToEmail
	if len(strReplyToName)>0 then
		Mailer.ReplyTo = strReplyToEmail
	end if
	Mailer.RemoteHost = strMailServer
	Mailer.Subject    =  strContactFormSubject
	Mailer.ContentType = "text/html"
	Mailer.BodyText = strLetter
	response.write "Mail Component used: SMTPsvg.Mailer version " & Mailer.version & "<br/>"
	if Mailer.SendMail then
		SendLetters = "Mail sent."
	else
		SendLetters = "Mail send failure. Error was " & Mailer.Response
	end if
case "CDONTS"
	Set mailer = CreateObject("CDONTS.NewMail")
    Mailer.From= strFromEmail
    Mailer.To=strToEmail
	if len(strReplyToName)>0 then
		Mailer.Value("Reply-To")  = strReplyToEmail
	end if
    Mailer.Subject=strContactFormSubject
	Mailer.BodyFormat=0
    Mailer.MailFormat=0
	Mailer.Body = strLetter
	response.write "Mail Component used: CDONTS<br/>"
    Mailer.Send
    SendLetters = "No confirmation with CDONTS"
case "CDOMESSAGE"
	Set mailer = CreateObject("CDO.message")
    Mailer.From= """" & strFromName & """<" & strFromEmail & ">"""
	if len(strReplyToName)>0 then
		Mailer.ReplyTo = """" & strReplyToName & """<" & strReplyToEmail & ">"""
	end if
    Mailer.To=strToEmail
    Mailer.Subject=strContactFormSubject
	Mailer.HTMLBody = strLetter
	response.write "Mail Component used: CDO.Message<br/>"
    Mailer.Send
    SendLetters = "No confirmation with CDO.MESSAGE"
case "PERSISTS.MailSender"
	Set Mailer = Server.CreateObject("Persits.MailSender")
	Mailer.Host       = strMailServer
	Mailer.FromName   = strFromName
	Mailer.From       = strFromEmail
	Mailer.AddAddress strToEmail,strToName
	if len(strReplyToName)>0 then
		Mailer.AddReplyTo strReplyToEmail,strReplyToName
	end if
	Mailer.Subject    =  strContactFormSubject
	Mailer.isHTML = True
	Mailer.Body = strLetter
	response.write "Mail Component used: Persits.MailSender version " & Mailer.version & "<br/>"
case "ASPSMARTMAIL"
	Set Mailer = Server.CreateObject("AspSmartMail.SmartMail")
	Mailer.SenderName   = strFromName
	Mailer.SenderAddress= strFromEmail
	Mailer.Recipients.Add strToEmail, strToName
	Mailer.server = strMailServer
	Mailer.Subject    =  strContactFormSubject
	Mailer.ContentType = "text/html"
	Mailer.Body = strLetter
	response.write "Mail Component used: AspSmartMail.SmartMail<br/>"
	SendLetters = "Mail Sent."
	On Error Resume Next
    Mailer.Send
    If Err <> 0 Then
    	SendLetters = "Error message: " & Err.Description
    end if
case "JMAIL"
	Set Mailer = Server.CreateObject("JMAil.Message")
	Mailer.FromName   = strFromName
	Mailer.From= strFromEmail
	Mailer.Subject    =  strContactFormSubject
	mailer.AddRecipient strToEmail, strToName
	Mailer.HTMLbody = strLetter
	Mailer.Charset      = "UTF-8"
	Mailer.MailServerPassWord=gv_MailServerPassWord
	Mailer.MailServerUserName=gv_MailServerUserName
	response.write "Mail Component used: JMAIL<br/>"
	Mailer.Send(strMailServer)
end select
 
response.write X & " Letter to " & strToName & " - " & strToEmail  & "; from: " & strFromName & " (" & strFromEmail & "); Results: " & SendLetters & "<br/>"
 
%>
 
</body>
 
</html>

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE