• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 356
  • Last Modified:

Emails in Japanese sent from the server are received badly encoded on client side

We have a problem in Email sending with japanese text. We are using following code
   Set ObjPerMail = Server.CreateObject("Persits.MailSender")
   ObjPerMail.Host = global_mail_host
   ObjPerMail.Port = global_mail_port
   ObjPerMail.Username = global_mail_username
   ObjPerMail.Password = global_mail_password
     ' ObjPerMail.CharSet = "UTF-8"
     'ObjPerMail.ContentTransferEncoding = "Quoted-Printable"
   ObjPerMail.From = fromemail
   ObjPerMail.IsHTML = True
   ObjPerMail.AddAddress toemail
   ObjPerMail.Subject = "????????:"
   ObjPerMail.Body = "????????:"

'   ObjPerMail.CharSet = "shift_jis"
'     ObjPerMail.ContentTransferEncoding = "Quoted-Printable"

   Set ObjPerMail = nothing

We tried the following encoding Shift-Jis, EUC-JP, ISO-2022-JP but none worked.

Any idea of how we can solve it?

Thanks a lot,

  • 10
  • 6
1 Solution
b0lsc0ttIT ManagerCommented:
Which email object is that?  You might want to make sure the object can handle those encodings (if you have a manual, etc).

Let me know more about the object but that might be the issue.

b0lsc0ttIT ManagerCommented:
If the object is AspEmail then check to see if you have the Premium version of that object.  Let me know.  You definitely won't be able to set the encoding or charset if using a version below Premium.

b0lsc0ttIT ManagerCommented:
Assuming the object is AspEmail (by Persits) and you have Premium then I have a little more info but may need some answers to be more specific.

Where is the Japanese text coming from?  You should make sure your ASP script doesn't change or mess up the encoding.  See the link below for an example of using Session.CodePage and let me know if you need a value for a specific encoding.  The number for utf-8 is in the example.

You will need to use both ContentTransferEncoding and CharSet.  There are examples of there use in the page and there is a table at the end with accepted values for Charset.


This might be all you need if the info above doesn't help.  Let me know if you have a question or need more info.

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

kustielAuthor Commented:
Hi Bol,

Thanks for your answers.

We are using AspEmail (by Persits)  and it is Premium version

If the Japanese text comes from FORM variables it works,
but if we hard code the text in ASP or read content from text file it is not working. Any idea?

Thanks, Assaf
b0lsc0ttIT ManagerCommented:
Thanks for those answers and info.

Please let me know about the code page for the script.  If you don't know if the use Response.Write to show it.  For example ...

   Response.Write "The code is " & Session.CodePage

If you response.write the hard coded text or the text from the text file how does it appear?  Is the email body html or text?

If it is html then try including the meta tag to specify the content-type.  I would also like you to try sending just a text/plain email (no html).  Take a look at the headers of the email message (when received) to see if that provides a clue, especially look at the content-type, etc.

Are you testing this using different email clients or programs to get the messages?  Just wanted to eliminate the chance that the issue is email "program" related.

Let me know if you have a question about any of this.

kustielAuthor Commented:
Hi bol,

CodePage is 65001
it does not show correct when we response.write the file content
in email we see following in header
Content-Type: text/plain;charset="UTF-8"
Content-Transfer-Encoding: Quoted-Printable
we are sending test mails to gmail and seeing in browser

Does this help you to think of a solution?

Thanks, Assaf
b0lsc0ttIT ManagerCommented:
Thanks for that info.  Very helpful.  What if the Japanese is hardcoded and you response.write with code 65001?  What is the result?

kustielAuthor Commented:
Hi bol,
It still doesn't show the chars correctly... what shall we do?
Thanks, Assaf
b0lsc0ttIT ManagerCommented:
I can't say for sure if this will fix the issue but I hope it will at least help.  The fact that a response.write doesn't show the characters (from the text file or manually entered) is troubling.  I hope it is related.  At the top of the script put the codepage line like ...

Session.CodePage = 932 ' Japanese support

Can you see the manually type Japanese character when you response.write them?  What about response writing the text file with characters?

Make sure as you test this you don't have an add header script line or html meta tag that specifies a different charset.  If leaving them out doesn't work for the tests above then add the html meta tag and use shift_jis.

<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">

If this works then let's try the email again and see if that works too.  Let me know if you have a question or need more info.

When you try the email next let me see the latest version of the code you have above.  In that code both blocks setting the charset, etc were commented out.  Please repost so I can see the current and see which you are actually using.  I would think shift_jis is the best to go for and it does seem to be supported by ASPEmail.

kustielAuthor Commented:

this also didn't work.

Here's the script:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=shift_jis">
<TITLE>AspEmail: Unicode.asp</TITLE>

Session.CodePage = 932  ' shift_jis code

Function getContent
      Set objFSO = server.CreateObject("Scripting.FileSystemObject")
      Set objFile = objFSO.GetFile(server.MapPath("faq.asp"))
      If objFile.Size > 0 Then
            Set objReadFile = objFSO.OpenTextFile(server.MapPath("faq.asp"), 1)
            strContents = objReadFile.ReadAll
            getContent = "" & strContents
            getContent = ""
      End If
End Function

If Request("Send") <> "" Then
   Set Mail = Server.CreateObject("Persits.MailSender")
   ' enter valid SMTP host
         Mail.Host = global_mail_host
         Mail.Port = global_mail_port
         Mail.Username = global_mail_username
         Mail.Password = global_mail_password
      Mail.IsHTML = True
      st = getContent()
   strsub = Request("Subject")
   Mail.From = "info@aspemail.com" ' From address
   Mail.FromName = Mail.EncodeHeader(Request("FromName"), "shift_jis")
   Mail.AddAddress Request("To")

   ' message subject
'   Mail.Subject = Mail.EncodeHeader( Request("Subject"), "shift_jis")
   Mail.Subject = Mail.EncodeHeader( strsub, "shift_jis")

   ' message body
   Mail.Body = st '& Request("Body")

   ' shift_jis parameters
   Mail.CharSet = "shift_jis"
   Mail.ContentTransferEncoding = "Quoted-Printable"
   Mail.Send ' send message
   Response.Write "Message sent to " & Request("To")
End If

<FORM METHOD="POST" ACTION="t_template.asp">
<TR><TD>Enter email:</TD><TD><INPUT TYPE="TEXT" NAME="To"></TD></TR>
<TR><TD>Enter your name:</TD><TD><INPUT TYPE="TEXT" NAME="FromName"></TD></TR>
<TR><TD>Enter Subject:</TD><TD><INPUT TYPE="TEXT" NAME="Subject"></TD></TR>
<TR><TD>Enter Body:</TD><TD><TEXTAREA cols="50" rows="10" NAME="Body"></TEXTAREA></TD></TR>

Anymore ideas?

Thanks, Assaf
b0lsc0ttIT ManagerCommented:
I haven't been able to come up with any other ideas yet.  However I do have 2 comments and one of those may be the fix.

The codepage line needs to be one of the first lines, usually the first.  It would definitely need to be before the html is sent, etc.

Can you elaborate a little more on it "didn't work"?  I appreciate you trying my suggestions but does that really mean that you can't even see the characters on the web page (not just the email body)?

Let me know if you have a question.  I am going to keep looking over this but I have run out of options right now.  Unfortunately I can't test the email object or the japanese characters myself so it make diagnosing this harder.  Thanks again for all the responses.

kustielAuthor Commented:
Hi bol,

Here are some stuff that I tried and the results:

1.) in this mail,
subject used with request.form variable
and body is content from external file by reading content
this content displays correctly in screen but not in email

---------- Forwarded message ----------
From: xxxxxxxxxxxxxxx
Date: Oct 24, 2007 12:17 AM
Subject: Ï;’ÏOkoi“j™’c_‰DDgYK?
To: xxxxxxxxxxxxxxxx

test è,-åf ç"»ã,'æ ã 㠫㠯㠩ã,"ã ªå?TçoYã,'é? ã £ã Yã,?ã "ã "ã §ã Tã

2.) in this mail, i have hardcoded japanese content in variable and used in body .
like this
st = "test –Ï;’ÏOkoi“j™’"
Mail.Body = st
but body came wrongly

---------- Forwarded message ----------
From: xxxxxxxxxxxx
Date: Oct 24, 2007 12:21 AM
Subject: Ï;’ÏOkoi“j™’c_‰DDgYK?
To: xxxxxxxxxxx

test èå’ ç"»ã'æ ã 㠫㠯㠩ã"ã ªå "çSxã'é¬

3.) this one i hardcoded japanese text directly in body like
 Mail.Body = "test –Ï;’ÏOkoi“j™’ spr "
but not worked

---------- Forwarded message ----------
From: xxxxxxxxxxx
Date: Oct 24, 2007 12:24 AM
Subject: Ï;’ÏOkoi“j™’c_‰DDgYK?
To: xxxxxxxx

test èå’ ç"»ã'æ ã 㠫㠯㠩ã"ã ªå "çSxã'é¬ spr

What do you say? Any new ideas?

Thanks, Assaf
b0lsc0ttIT ManagerCommented:

I don't have any new ideas.  Unfortunately there is no way for me to test this with the mail object you use and I have not been able to find or think of other suggestions.

Let me know if there is something else I can help you with for this question.  Let me know if you have a question about closing it or your options.

kustielAuthor Commented:
Hi Bol,

If I'll give you the FTP details, will you be able to try and see if you can fix the code so that the emails in Japanese will be sent successfully?

Thanks, Assaf
b0lsc0ttIT ManagerCommented:

Thanks for the offer.  To be honest I don't know that it will make a difference if I could test it myself.  You have been very responsive and seem to have done the tests I would do.  However I am willing to try.  It won't be proper for us to take this away from EE and we can't keep other experts from it.  Since this info is sensitive I would not want you to post it but if you are willing to share then is that open to any expert here?  If not, then we probably can't pursue it.  If that is OK then send it the info to the email in my profile.  I will keep the info and make it available to any expert involved here that asks for it.

I won't and you shouldn't move the "conversation" on this to email though.  I'll continue to post here to work on this.  If all of this is acceptable to you then I am happy to try.  This way it should work for the member rules and be fair to other experts.

Let me know if you have a question about any of this.

b0lsc0ttIT ManagerCommented:
What was the status of this?  I noticed you closed it but assigned a B grade.  It seems to me that you never did get an answer to this.  If that is true then this should be deleted.  We could even refund your points if you reply.

Please let me know the status of this.  If I did help then I am glad but I don't want points just to close this and it won't be helpful to the database if there is no answer or info.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 10
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now