<<Back To Faq 4.9


Complete FAQ Listing


4.9 How do I send non US-ASCII emails? Printer Friendly

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 ISO-8859-1 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: http://www.aspnetemail.com/charsets.aspx .

The following example demonstrates this technique.

[ C# ]
 	public static void NonAsciiMail()
        {
            //create the mail message
            MailMessage mail = new MailMessage();

            //set the addresses
            mail.From = new MailAddress("me@mycompany.com");
            mail.To.Add("you@yourcompany.com");

            //set the content
            mail.Subject = "This is an email";

            //to send non-ascii content, we need to set the encoding that matches the 
            //string characterset.
            //In this example we use the ISO-8859-1 characterset
            mail.Body = "this text has some ISO-8859-1 characters: âÒÕÇ";
            mail.BodyEncoding = Encoding.GetEncoding("iso-8859-1");

            //send the message
            SmtpClient smtp = new SmtpClient("127.0.0.1");
            smtp.Send(mail);

        }

[ VB.NET ]
    Public Sub NonAsciiMail()
        'create the mail message
        Dim mail As New MailMessage()

        'set the addresses
        mail.From = New MailAddress("me@mycompany.com")
        mail.To.Add("you@yourcompany.com")

        'set the content
        mail.Subject = "This is an email"

        'to send non-ascii content, we need to set the encoding that matches the 
        'string characterset.
        'In this example we use the ISO-8859-1 characterset
        mail.Body = "this text has some ISO-8859-1 characters: âÒÕÇ"
        mail.BodyEncoding = Encoding.GetEncoding("iso-8859-1")

        'send the message
        Dim smtp As New SmtpClient("127.0.0.1")
        smtp.Send(mail)
    End Sub 'NonAsciiMail 

 



The formatted version of this faq can be found at http://www.SystemNetMail.com/faq/4.9.aspx