Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Encoding of email subject lines - garbled international characters

Posted on 2004-09-28
Medium Priority
Last Modified: 2008-01-09

My website (IIS6,, has to send out several email messages, some in html, some in text, and the encoding of international characters works well throughout the site. However, the subject lines of emails being sent refuse to accept the encoding provided.

Example: Appétit in the source shows up properly as Appétit's in the html (even in the page title) and the body of the email, but not in the subject line of an email.

Why is that and what can I do? I have tried several globalization settings in the web.config and also looked into encoding properties of the mailmessage class - but there's only bodyEncoding, so I didn't experiment there.

Question by:ddetering
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 17

Accepted Solution

AerosSaga earned 375 total points
ID: 12175885
heres your answer:

 3.1 How do I send non US-ASCII emails? Printer Friendly   Email This FAQ   Discuss
In the beginning, when email was first being used, it was all us-ascii content. To handle different languages and character sets, different encodings must be used. The following example demonstrates sending a non us-ascii email, using the Chinese GB2312 character set as an example. The hardest part of sending non us-ascii email, is to determine the correct character set. For reference, an easy to use character set chart can be found at aspNetEmail's website, here: .

Note: There is one major pitfall with this technique. The original email rfcs required that all non us-character sets use the quoted-printable or base64 content transfer encoding (convert all characters above 127, to 2 or more bytes, so the individual byte value is less than 128). Email readers, then take these bytes, and convert them back to the original character set. System.Web.Mail does not encode higher end character sets. Instead, it just sends the characters unencoded (commonly known in the email world as 8 bit encoding). Thus, if your email recipient's mail server, or gateway, does not support 8 bit encoding, they will not receive the email. THERE IS NO WAY PROGRAMMATIC WAY OF CHECKING FOR THIS. The only way, is make sure the email message is properly encoded using the quoted-printable (preferred) or base64 content transfer encoding. If you are sending a newsletter, this can be a huge problem, because your newsletter will simply not be delivered, and there is a good chance, you will never know it. As an email vender, I've had customer after customer encounter this problem. And it has always been fixed by using the quoted-printable format. Because this cannot be controlled using System.Web.Mail, you will need to use a third party product like aspNetEmail. The bottom line is this: if you need to send emails, using a higher end character set, DO NOT USE System.Web.Mail. Either roll your own component (if you have the time), or purchase a third party product that properly encodes email messages.

For those people that don't have a choice, and have to use System.Web.Mail, the following is a code snippet demonstrating sending a non us-ascii email.
[ C# ]

MailMessage mail = new MailMessage();
mail.To = "";
mail.From = "";
mail.Subject = "this is a test email.";
mail.Body = "Some Chinese characters or text goes here";
mail.BodyEncoding = System.Text.Encoding.GetEncoding( "GB2312" ); //set the proper character set here
SmtpMail.SmtpServer = "localhost";  //your real server goes here
SmtpMail.Send( mail );

[ VB.NET ]

Dim mail As New MailMessage()
mail.To = ""
mail.From = ""
mail.Subject = "this is a test email."
mail.Body = "Some Chinese characters or text goes here"
mail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312") 'set the proper character set here
SmtpMail.SmtpServer = "localhost" 'your real server goes here



Author Comment

ID: 12175973
Thank you, Aeros. I have tried your code snippets (just to make sure) and set the mail.bodyencoding to several options, but the subject line remained flawed. Are you saying that with AspNetEmail I will be able to send other characters from my application? (I know that GroupMail can - encoding "western european / americas").
LVL 17

Expert Comment

ID: 12176188
Your referencing the ones in your web.config here?

System.Text.Encoding.GetEncoding("GB2312") 'set the proper character set here

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Author Comment

ID: 12176406
Not sure whether I understand your question. I set the encoding in the web.config:
 <globalization requestEncoding="ISO-8859-1" responseEncoding="ISO-8859-1" />
 and assume that it will be the default one for mailmessage.bodyencoding. But then I have also set mailmessage.bodyencoding to UTF-8 and ASCII. None yielded any different result.
LVL 17

Expert Comment

ID: 12178813
check into setting your response encoding in your web.config:

Visual Basic and Visual C# Concepts       
Editing the Web.config File for Web Forms Globalization

Web Forms configuration files, named Web.config, provide settings for every Web Forms page in the same directory as the configuration file. The settings are usually also inherited by subdirectories. Each file can contain a globalization section in which you can specify default encodings and cultures. Values are valid if they are accepted by the related Encoding and CultureInfo classes. For more information on the contents of the Globalization section, see <globalization> Element. For general information on Web.config files, see ASP.NET Configuration.

The Web.config file is case-sensitive, so specifying a value for "FileEncoding" will not have the desired effect, but specifying a value for "fileEncoding" will. For more information, see Format of ASP.NET Configuration Files.

To edit the Web.config file

    * Set the values of fileEncoding, requestEncoding and responseEncoding to specify the way in which .aspx files, request data and response data are encoded. For more information on encoding values, see Selecting an Encoding for Web Forms Globalization

      If the file encoding is specified in the Web.config file, the actual file must be saved in the same encoding. To select an encoding different from the system default, use the Advanced Save Options dialog box (available on the File menu).
    * Set the values of culture and uiCulture. For more information on culture values, see Setting the Culture and UI Culture for Web Forms Globalization.


          Note   The attributes of the globalization section in the Web.config file can also be specified in the @ Page directive (with the exception of fileEncoding, which can only be specified in Web.config because it applies to the file itself). Settings in the Page directive are only valid for a specific page and override the settings of the Web.config file.

Thats really the only other thing I can think of


Author Comment

ID: 12192871
I can't get it work with the system.web.mail class. Just have sent an inquiry to aspnetmail whether their product does it.

Author Comment

ID: 12213731
Okay, based on their answer, aspnetmail wouldn't have any problems with this issue and it seems that the system.web.mail class cannot encode any non-us ascii characters in the subject line. This is the short but comprehensive answer. Aeros had this buried somewhere in his first answer, so s/he's getting the points.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question