Lack of Permission in Interop.Outlook when sending Email

0

I have an asp.net application in C# running IIS 7 on Windows 7.

An email is sent out when a certain event occurs, driven by the client user.

The code is as below: I am using Outlook Interop instead of Exchange SMTP server since the smtpClient is being blocked by McAfee and I am not allowed to change McAfee settings.

We have enterprise license for Office including Outlook, so licensing is not an issue.

When trying to send an email, following error is thrown:

System.Runtime.InteropServices.COMException (0x80030005): You don't have appropriate permission to perform this operation. at Microsoft.Office.Interop.Outlook.ApplicationClass.CreateItem(OlItemType ItemType) at in <.cs file name>.

IIS application pool is using NetworkService as ProcessModel identity. I also checked DCOMCNFG and it has Network service as an authorized user with appropriate permissions.

How can I fix this?

    using outlook = Microsoft.Office.Interop.Outlook;

    outlook.Application olkApp1 = new outlook.Application();

            outlook.MailItem olkMail1 = (outlook.MailItem)olkApp1.CreateItem(outlook.OlItemType.olMailItem);
            outlook.Accounts accounts = olkApp1.Session.Accounts;
            foreach (outlook.Account account in accounts)
            {
                if (account.SmtpAddress == "")
                {
                    olkMail1.To = toEmail;
                    if (ccEmail != null)
                    {
                        olkMail1.CC = ccEmail;
                    }
                    olkMail1.Subject = subjEmail;
                    olkMail1.Body = bodyEmail;
                    //olkMail1.Attachments.Add(filePath, outlook.OlAttachmentType.olByValue, 1, "attachment");
                    olkMail1.Save();
                    olkMail1.SendUsingAccount = account;
                    ((outlook._MailItem)olkMail1).Send();
c#
asp.net
email
outlook
office-interop
asked on Stack Overflow May 4, 2015 by user3150378 • edited May 4, 2015 by John Saunders

1 Answer

2

Outlook cannot be used from a service (such as IIS). Outlook was never designed to work from a service; it can and will display user prompts that no user will be able to dismiss.

Your options are

  1. Extended MAPI, but it is only accessible from the C++ or Delphi

  2. Exchange Web Services - see https://msdn.microsoft.com/en-us/library/office/dd877012(v=exchg.150).aspx

  3. Redemption - it is an Extended MAPI wrapper that can be used from a service in any language including C#, VB.Net or VB script:

answered on Stack Overflow May 4, 2015 by Dmitry Streblechenko • edited May 4, 2015 by Dmitry Streblechenko

User contributions licensed under CC BY-SA 3.0