Why do I get 5.5.4 Invalid Address error?

浪子不回头ぞ 提交于 2019-12-13 17:27:28

问题


I tried to send an email using the following code:

MailMessage message = new MailMessage();

        message.From = new MailAddress(fromMailAddress.Trim());
        message.To.Add(new MailAddress(toMailAddress.Trim()));

        message.Subject = subject;
        message.Body = body;
        message.SubjectEncoding = System.Text.Encoding.UTF8;
        message.BodyEncoding = System.Text.Encoding.UTF8;
        SmtpClient client = new SmtpClient();
        try
        {
            client.Send(message);
        }
        catch(Exception e)
        {
            throw e;
        }

However, I got the exception:

The server response was: 5.5.4 Invalid Address

The from email, to email, server host name and port are all correct. The exact same code, with exact same input values works on another machine in our office


回答1:


Found out the answer after some thorough debugging.

Turns out my machine name has an 'å'-character (invalid Swedish character) in it. After changing that, it worked.




回答2:


There was a KB released for System.Net.Mail that affected address parsing and Unicode so the reason it worked on one machine and not the other was likely the presence of this KB. .NET 4.0 also has some significant improvements in parsing email addresses.



来源:https://stackoverflow.com/questions/1200486/why-do-i-get-5-5-4-invalid-address-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!