StmpClient does not seems to use NetworkCredential

G

Guy

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;
 
M

Miroslav Stampar

Probably TLS/SSL needed:

string from = "(e-mail address removed)";
string to = "(e-mail address removed)";
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:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top