Exchange 2007 does not allow sending mail from a console application

I am trying to send an email using Exchange 2007 from a console application using the following code and I am getting this error message in an exception that is being thrown to challenge the send.

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

MailMessage message = new MailMessage();
message.From = new MailAddress("from@example.com");
message.To.Add("to@domain.com");
message.Subject = "test";
SmtpClient smtp = new SmtpClient(ConfigurationUtil.SMTPServer);
smtp.Credentials = new System.Net.NetworkCredential("from@example.com", "password");
smtp.Send(message);

      

This worked on Exchange 2003.

0


a source to share


2 answers


This turned out to be an Exchange 2007 issue and had nothing to do with the code.



+1


a source


From the error message, it sounds like you need to connect to Exchange over SSL.

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

      



Substitute this port number for the port that the Exchange server is listening on for secure connections.

0


a source