Is it me or is there a bug in the MailAddress class in System.Net.Mail?
This code will always throw an excpetion:
MailMessage mail = new MailMessage();
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
mail.Subject = "Test email"
mail.IsBodyHtml = true;
mail.Body = "<b>Does not work</b>";
//Connect to server and send message.
SmtpClient smtp = new SmtpClient();
smtp.Host = "mailserver.me.com";
smtp.Send(mail);
The exception I get is this:
System.FormatException: The specified string is not in the form required for an
e-mail address.
However, according to wiki, a dash is a valid character in the local part.
Does anyone know a way of using the System.Net.Mail classes to send an email to someone with a dash in the email address?