Probably TLS/SSL needed:
string from = "me@example.com";
string to = "yo*@example.com";
string username = "username";
string password = "password";
System.Net.Mail.MailMessage email = new
System.Net.Mail.MailMessage(from, to);
email.Body = "Hi";
System.Net.Mail.SmtpClient mailClient = new
System.Net.Mail.SmtpClient();
System.Net.NetworkCredential basicAuthenticationInfo = new
System.Net.NetworkCredential(username, password);
mailClient.Host = "smtp.example.com";
mailClient.Port = 587; //preferred port for sending SMTP
messages (if it doesn't work just remove this line)
mailClient.EnableSsl = true; //!!!!!important!!!!!!!!
mailClient.UseDefaultCredentials = true;
mailClient.Credentials = basicAuthenticationInfo;
mailClient.Send(email);
Miroslav Stampar MCSD, Security+
http://mstampar.awardspace.com
Guy je napisao/la:
I use SmtpClient to send mail. My customer reported that sending mail
was throwing an exception on his machine "the SMPT client requires a
secure connection or the client was not authenticated".
so I now provide credentials with my request, however it sends mail
all the time, whichever username or password I use. I even removed the
password from my Outlook account options. Sends mail anyway ?
Is there a credential cache in Windows taking effect ?
cred = new NetworkCredential(strUserName, strPassword);
smtp = new SmtpClient();
smtp.Host = strMailHost;
smtp.UseDefaultCredentials = false;
smtp.Credentials = cred;