The SmtpClient.Send () method throws this exception when I try to send an email to an address containing an underscore (Ă©):
System.Net.Mail.SmtpException: The client or server is configured only for email addresses with local ASCII parts: léo.xxx@example.com.
in System.Net.Mail.MailAddress.GetAddress (boolean allowUnicode)
in System.Net.Mail.SmtpClient.ValidateUnicodeRequirement (MailMessage ...)
in System.Net.Mail.SmtpClient.Send (MailMessage message)
The wording of the message makes me think that there may be a setting that I can activate to make this work, although I did not find anything on this subject.
I tried several SMTP servers, including Gmail. Here are the relevant bits to play:
The code
var msg = new MailMessage(); msg.Subject = "Test"; msg.From = new MailAddress("xxx@gmail.com"); msg.To.Add(new MailAddress("léo.yyy@gmail.com")); new SmtpClient().Send(msg);
app.config
<system.net> <mailSettings> <smtp from="xxx@gmail.com"> <network host="smtp.gmail.com" port="587" userName="xxx@gmail.com" password="password" enableSsl="true" /> </smtp> </mailSettings> </system.net>
Xavier poinas
source share