SmtpException: client or server configured only for email addresses with local ASCII parts

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> 
+13
c # smtpclient smtp
source share
3 answers

.net only supports ASCII characters. I do not believe that it supports extended ASCII characters (including accented e).

http://www.asciitable.com/

We encountered the same problems when users tried to use the Danish character for a / e.

-6
source share

If the DeliveryFormat property of your SmtpClient instance is set to SmtpDeliveryFormat.SevenBit (default), you need to make sure that your SMTP gateway responds with SMTPUTF8 when sending EHLO via .NET while trying to send email. SmtpClient uses this to determine if the gateway is capable of supporting UTF8.

If DeliveryFormat is SmtpDeliveryFormat.International , you can send independently.

+14
source share

Late answer, but I solved it by specifying the encoding as follows:

 var mailMessage = new MailMessage { From = new MailAddress("test@domain.co.zw", "Test User", Encoding.UTF8) } 

In my case, the server was causing an error.

+1
source share

All Articles