Programmatically Send Email from Service

  • Thread starter Thread starter Brian Reed
  • Start date Start date
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
 
Back
Top