1

I need to send an email to a recipient with international characters in the email address. An example email would be:

GaÙl@asterixthe.com

I've done quite a bit of searching but the information I'm finding is for the body and not the recipient. Do I need to mime encode this in some way and if so, how?

The code I've got is below:

 MailMessage mailMessage = 
    new MailMessage(email.SenderEmailAddress, email.RecipientEmailAddress, "Why hello there!", emailMessage)
    {
        IsBodyHtml = true,
        BodyEncoding = new System.Text.UTF8Encoding()
    };


 SmtpClient smtpClient = new SmtpClient("localhost")
 {
    Port = 25,
 };
 smtpClient.Send(mailMessage);

Thanks,

Simon

Edit: Here's the exception

System.FormatException: The specified string is not in the form required for an
e-mail address.
   at System.Net.Mime.MailBnfHelper.ReadMailAddress(String data, Int32& offset,
String& displayName)
   at System.Net.Mime.MailBnfHelper.ReadMailAddress(String data, Int32& offset)
   at System.Net.Mail.MailAddressCollection.ParseValue(String addresses)
   at System.Net.Mail.MailAddressCollection.Add(String addresses)
   at System.Net.Mail.Message..ctor(String from, String to)
   at System.Net.Mail.MailMessage..ctor(String from, String to)
   at System.Net.Mail.MailMessage..ctor(String from, String to, String subject,
String body)
Greg B
  • 14,597
  • 18
  • 87
  • 141
Simon
  • 984
  • 1
  • 8
  • 24

1 Answers1

0

Ok,

Reading the documentation for the MailMessage class in the .Net framework, I found that one of the constructors of the class receives a MailAddress object.

According to MSDN (http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.aspx), the DisplayName property can contain non-ASCII characters, I would think that if they specify that explicitly is because the Name cannot have them.

Have you tried the suggestion on the other thread, the one saying that you could use "punycode"?

willvv
  • 8,439
  • 16
  • 66
  • 101
  • I tried using MailMessage but without success. I wondered if this was a constraint of having to use .NET 2 for this particular app. As far as puny code - I'll have a look at it again. Thanks. – Simon Dec 10 '10 at 15:39
  • Accepted this answer even though I'm still stuck with it. I think a 3rd party component may do it but .NET 2 does not and I'm happy with that as its a draft standard. – Simon Dec 14 '10 at 08:40