Probably TLS/SSL needed:
string from = "me@example.com ";
string to = "yo*@example.co m";
string username = "username";
string password = "password";
System.Net.Mail .MailMessage email = new
System.Net.Mail .MailMessage(fr om, to);
email.Body = "Hi";
System.Net.Mail .SmtpClient mailClient = new
System.Net.Mail .SmtpClient();
System.Net.Netw orkCredential basicAuthentica tionInfo = new
System.Net.Netw orkCredential(u sername, password);
mailClient.Host = "smtp.example.c om";
mailClient.Port = 587; //preferred port for sending SMTP
messages (if it doesn't work just remove this line)
mailClient.Enab leSsl = true; //!!!!!important! !!!!!!!
mailClient.UseD efaultCredentia ls = true;
mailClient.Cred entials = basicAuthentica tionInfo;
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 NetworkCredenti al(strUserName, strPassword);
smtp = new SmtpClient();
smtp.Host = strMailHost;
smtp.UseDefault Credentials = false;
smtp.Credential s = cred;