Sending mail to addresses containing non-ASCII characters

If you require sending messages to email addresses which contain non-ASCII characters like “äöü”, that’s how it’s done. However, important to determine whether those characters are in domain or username part of email address.

If international characters are a part of domain name, you’ll need to convert domain name into Punycode. The following example demonstrates how it’s done with MailBee.NET Objects:

MailBee.Global.LicenseKey = "Trial or permanent key";
Smtp mailer = new Smtp();
mailer.Log.Enabled = true;
mailer.Log.Filename = @"C:\Temp\log.txt";

mailer.SmtpServers.Add("mail.domain.com", "jdoe", "secret");
mailer.From.Email = "jdoe@domain.com";
mailer.From.DisplayName = "John Doe";
EmailAddress addr = new EmailAddress("jane.doe@äöü.com", "Jane Doe");
mailer.To = addr.ToIdnAddress();

mailer.Subject = "Sending mail to addresses containing non-ASCII characters";
mailer.BodyHtmlText = "This is a sample mail message.";

mailer.Send();

It is perfectly safe to use this method for addresses which don’t contain any international characters, you’ll just get the new object which has the same values as the current one.

And if those characters are in username, not just in domain name – then you need to set Smtp.RequestEncoding property to UTF8. Bear in mind that many SMTP servers are unable to deal with international email addresses, so you may wish to check if particular SMTP server returns UTF8SMTP or SMTPUTF8 capability in EHLO response.

Sending mail to addresses containing non-ASCII characters

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s