Persits Software, Inc. Knowledge Base Articles

AspEmail - Problems with foreign and Unicode characters

Problem Description

When sending a message with AspEmail using foreign non-ASCII character sets, characters do not come through properly and appear as garbage.


There can be several causes of this type of problem.

1. Make sure you have upgraded to AspEmail 5.0 or later. Older versions did not have full support for foreign character sets. 5.0 is a free upgrade from any previous AspEmail purchase.

2. Make sure you are setting Mail.Charset to a valid value as described in the AspEmail Manual.

Mail.Charset = "UTF-8"

3. Set Mail.ContentTransferEncoding.

Mail.ContentTransferEncoding = "quoted-printable"

4. Set a page Codepage header, if your script is using hard-coded character constants. The value for Unicode UTF-8 is 65001; see Microsoft documentation for other locale-specific codepages.

<% @codepage=65001 %>

5. Set Session.CodePage with the same value.


6. To accept non-Ascii values typed into HTML forms, include an HTML META charset tag in the <HEAD> area of both the HTML form page and the ASP script page (these may be the same page):

<META HTTP-EQUIV="Content-Type" content="text/html; charset=utf-8">

7. Use EncodeHeader as specified in the AspEmail manual for headers such as Subject and From.

Mail.Subject = Mail.EncodeHeader("Unicode text here", "UTF-8")

8. Use the Request.Form collection explicitly to access all user posted data, not the generic Request collection.

Mail.Body = Request.Form("BodyText") 'like this
Mail.Body = Request("BodyText") 'not like this!

9. If you are building Mail.Body using string variables that are populated from a source such as a database, ensure that they contain valid data. Ensure that your data is not encoded already, as it will come out garbled if AspEmail re-encodes already-encoded data.

If you follow all these steps, AspEmail will format and send messages as per the MIME standards. Any further difficulty in displaying such messages will be due to the email client, not AspEmail itself.

We recommend using Unicode UTF-8 rather than specific localized character sets (Hebrew, Arabic, Russian, etc.) Unicode is now a mature, widely-supported standard that many programs and browsers deal with better than localized encodings.