Programmatically Send 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
 

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