Reputation: 75
I am trying to send en email to myself using .NET's SmtpClient, here is my code:
string email = ConfigurationManager.AppSettings["mailAddress"];
string password = ConfigurationManager.AppSettings["mailPassword"];
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587)
{
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(email, password)
};
MailMessage message = new MailMessage(from: email, to: email, subject: "subject", body: "body");
smtp.Send(message);
I keep getting this message: "The address has an invalid host name: infinitebankoftheuniverse@gmail.com"
What am I doing wrong? What is invalid about this address?
Upvotes: 0
Views: 393
Reputation: 2044
Copy infinitebankoftheuniverse@gmail.com from your answer and put it in Notepadd++ and you will see that it displays properly. If you encode in ASCII though, you will see that that is an extra unprintable character after your 'l' in gmail. It looks like this in ASCII: infinitebankoftheuniverse@gmailâ€.com
I'm not sure what that character is, but it would mess up the hostname.
Upvotes: 2