C#: Windows auto-mail service doesn't work
I wanted to create simple service, which would periodically download a list of e-mail adresses and send them e-mails.
I started writing the service, and before that I tested, if the e-mail sending works - and yes, i开发者_开发百科t does.
The problem is, that whereas I get no timeouts while sending e-mails by simply using the mailing method in Main() I get the timeouts and exceptions, when I try to do the same while executing the code as a service (using InstallUtil.exe, then going to My computer/manage and starting the service)
I guess it has to be some permissions/privileges issue, but have completely no idea, how to solve it - I tried to turn the firewalls off with no effect. When I call the mailing method in onStart(), onStop() methods or in the thread that the service starts - I'm unable to "connect to remote server". I tried using different ports and SMTP servers, but it's all the same - it works as long as I run the code in a non-service program. I tried different service settings - LocalSystem, NetworkService itp - all the same.
The same goes with any changes to the Windows Registry - I can do the reading/writing while the Main() is being executed or even in the service installer - but it doesn't work when the service wants to use it.
Please help!
Services run under a different account. (Typically SERVICE)
You need to make sure that your code accounts for this. When you are running in an interactive mode, you are running with your current credentials.
Are you recording all exceptions to a log file? Since a service has no user interface, you will need to record any errors either to a log file or to the event log.
精彩评论