My computer is running Windows 7 Pro with 8GB RAM and I have administrative access.
I am using Visual Studio 2010 Professional with C#.
The computer is on a University network with a Windows 2008 domain, and is going through the University mail server so it is not an issue of a firewall blocking port 587 as it will work when I run it under may own account.
I am writing a windows service to monitor a database at regular intervals and when as certain set of conditions is right it will email the appropriate person a reminder.
The database actions are all working fine so there is no problem there.Where I do have a problem is when I run this program as a normal executable it will correctly send the smtp email.For this is use the following authentication:
The email message is correctly formed specifying To, From, Subject, Body
SmtpClient client = newSmtpClient(“mailserver.co.uk”, 587);
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = true;
client.Send(message);
When I run the same program as a Windows service I have to provide different authentication so that it will continue to work even when I am logged out, which I do using:
SmtpClient client = newSmtpClient(“mailserver.co.uk”, 587);
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(“myAccount@mailserver.co.uk”,”MyPassword”)
client.Send(message);
The exception message that is thrown is:
EXCEPTION: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated
at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at DionysiaWcfServiceLibrary.DionysiaServiceLibrary.DirectMailer(MailDespatch email)
Everything that I have read always say to use:
System.Net.NetworkCredential(“myAccount@mailserver.co.uk”,”MyPassword”)
I have also tries using the smtp servers fully qualified name.
Any help would be greatly appreciated.
Many thanks in advance for your time and effort.