Sending mail from a Windows Service App fails

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

H
I have a .NET application that uses interop to send emails using outlook 2000. It works fine
I have altered it to run as a service and it fails in one of two ways
1. If I run the service using the system account then creation of the object fails after about 2 minutes. A message appears in the event log saying that DCOM has failed to respond within the timeout
2. If I run using an administrator account then creation of the objects works OK but when the mail message is actually sent the application fails immediately with the message "operation could not complete because the service provider does not support it"
Has anyone else had the same problem
Is this a DCOM issue, an outlook issue or a .NET issue
Thanks in advanc
Phil
 
Phil,

It's probably sort of a hybrid permission / Outlook issue.

Outlook will run under the "profile" of the currently logged-in user. The
first thing you have to do is make sure it's configured to work correctly
sending and receving interactively under the account that you'll be running
the service under.

Then you have to set up the service to allow it to "interact with the
desktop", and to use the account that Outlook is configured for, rather than
the default (system account).

I am also fairly sure that Outlook will tend to go insane if your Windows
service is running it under one account and anyone or anything else runs it
under a different account at the same time. It's probably safer if the
machine in question uses Outlook only for the Windows service. Failing
that, the Windows service should use the same account as the user who is
logged in. At any rate I would sure test the heck out of it if I were any
chance of using Outlook under multiple accounts at the same time.

If you just need to send emails, particularly in the background, you're
generally better off using an email library of some kind; Outlook can be
like driving a tack with a sledgehammer unless you really need integration
with its calendar or something along those lines ...

--Bob

Phil Norman said:
Hi
I have a .NET application that uses interop to send emails using outlook 2000. It works fine.
I have altered it to run as a service and it fails in one of two ways.
1. If I run the service using the system account then creation of the
object fails after about 2 minutes. A message appears in the event log
saying that DCOM has failed to respond within the timeout.
2. If I run using an administrator account then creation of the objects
works OK but when the mail message is actually sent the application fails
immediately with the message "operation could not complete because the
service provider does not support it".
 
I found the same problem and just reverted to SMTP mail, instead.... the
only catch is that you have
to find a way of supplying your SMTP server and a CC address in order to
retain copies of the
emails generated.

using System.Web.Mail;

....
private string m_smtpServer;

private string m_ccAddress;

....

public EMAIL(string SMTPServer)

{

m_smtpServer = SMTPServer;

m_ccAddress = null;

SmtpMail.SmtpServer = m_smtpServer;

}

private MailMessage GenerateMsg(string from, string to, string subject,
string message)

{

MailMessage msg = new MailMessage();

msg.To = to;

msg.Cc = m_ccAddress;

msg.From = from;

msg.Subject = subject;

msg.Body = message;

return (msg);

}

public void SendEMAIL(string from, string to, string subject, string
message)

{

SmtpMail.Send( GenerateMsg(from,to,subject,message) );

}
 
Back
Top