Monday, June 28, 2010

SMTH-AUTH errors with System.Net.Mail

net_v_webIf you are getting SMTH AUTH errors while trying to send e-mails using the SmtpClient to an smtp server that requires authentication, make sure that you call UseDefaultCredentials before settings the credentials.

So, order is important here!

using System.Net;
using System.Net.Mail;
using (var client = new SmtpClient())
client.Host = "";
  client.Port = 25;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(username, password);

Good luck!

No comments: