tags:

views:

23

answers:

1

Hi,

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.

Thanks, Jothi Prasad

A: 

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.

ho1
Hi mxmissile, Please find the code i am using to send mail: SmtpClient smtp = new SmtpClient("XXXX", 25); MailAddress from = new MailAddress("[email protected]","DRMUpdater"); MailAddress to = new MailAddress("[email protected]","DRM"); MailMessage email = new MailMessage(from, to); email.Subject = "DRMShell Updation Failed for user: " + userName; email.Body = String.Empty; smtp.Send(email); .
Hi ho,As the windows service is performing administrator related activities. I can change the service account.But i will change the account for testing. But is it possible to change the account at runtime..?
Not exactly sure what you mean but if you use the `SmtpClient.Credentials` property as I mention above you should be able to supply any credentials you want at runtime.And otherwise you could create a new account, give it admin rights on that box and make sure that it's authorised to send emails.
ho1