Troubleshooting "Failure sending mail" error when sending email via Windows service (works in Windows Forms application)
When i tried to send mail from Windows service, i got the exception with message "Failure sending mail".
The same code works in the windows forms application.
The windows service is running in local system account?
Kindly help me in resolving this issue.
Here is the code that sends the email:
SmtpClient smtp = new SmtpClient("XXXX", 25);
MailAddress from = new MailAddress("admdept@test.com","DRMUpdater");
MailAddress t开发者_JS百科o = new MailAddress("drm_dro3@test.com","DRM");
MailMessage email = new MailMessage(from, to);
email.Subject = "DRMShell Updation Failed for user: " + userName;
email.Body = String.Empty;
smtp.Send(email);
Is it possible that your SMTP server needs authentication? And it might be ok with your normal account, but the Local System
fails authentication.
You can try this either by setting the service to run under your account or by specifying specific credentials during the connection.
You can change the credentials by setting the UseDefaultCredentials
property to false
and creating a new NetworkCredential
in the property Credentials
.
精彩评论