Programmatically Sending Email from Service

B

Brian Reed

I have a service that is running on my machine that is configured as a
specific user. I am trying to having problems sending email from this
service. I am assuming it is because there is no interactive logon and the
service can't interact with the desktop.

Is there a way to send email throuhg Outlook without having an interactive
logon or access to the desktop?

Here is my code that sends the email:

Outlook._Application pOutlook = new Outlook.ApplicationClass();

object oMail = pOutlook.CreateItem(Outlook.OlItemType.olMailItem);

Outlook.MailItem pMailItem = oMail as Outlook.MailItem;

if(pMailItem != null)
{
pMailItem.Subject = strEmailSubject;
pMailItem.Body = strEmailBody;
pMailItem.Recipients.Add(strEmailAddress);

pMailItem.Send();
}

Here is the error message I am getting from the exception that is being
thrown:

Error Message: Unable to perform the operation. The server is not available.
Contact your administrator if this condition persists. Could not complete
the operation because the service provider does not support it.

Error Source: Microsoft Outlook



Any help would be great. Thanks,

Brian
 
G

Guest

No. The Outlook Object Model wasn't designed to be used from a service. If
you need to send e-mail, either recode your solution using Collaboration
Data Objects 1.21 or CDO for Windows 2000. (The later is for SMTP only and
doesn't put a copy in your mailbox. I use this library when building
automated nightly tasks that need to send a status notification.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top