views:

527

answers:

2

I am trying to send email using Exchange 2007 from a console app using the following code and I get this error message in the exception that gets thrown on the Send call.

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated

MailMessage message = new MailMessage();
message.From = new MailAddress("[email protected]");
message.To.Add("[email protected]");
message.Subject = "test";
SmtpClient smtp = new SmtpClient(ConfigurationUtil.SMTPServer);
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "password");
smtp.Send(message);

This worked on Exchange 2003.

A: 

From the error message it seems like you need to connect to Exchange via SSL.

SmtpClient smtp = new SmtpClient(ConfigurationUtil.SMTPServer, 465);

Substitute that port number for the port that your Exchange server's secure connection is listening on.

Jason Miesionczek
A: 

This ended up being an Exchange 2007 issue and had nothing to do with code.

MHinton
So what was the actual issue?
Jabezz
I needed a mail route opened on the Exchange server from the machine I was using so Exchange would accept mail sent from it.
MHinton