How to avoid Outlook security alert when reading outlook message from C# program

StackOverflow https://stackoverflow.com/questions/235231

  •  04-07-2019
  •  | 
  •  

Question

I have a requirement of reading subject, sender address and message body of new message in my Outlook inbox from a C# program. But I am getting security alert 'A Program is trying to access e-mail addresses you have stored in Outlook. Do you want to allow this'.

By some googling I found few third party COM libraries to avoid this. But I am looking for a solution which don't require any third party COM library.

Was it helpful?

Solution

Sorry, I have had that annoying issue in both Outlook 2003 and Outlook 2007 add-ins, and the only solution that worked was to purchase a Redemption license. In Outlook 2007 that pesky popup should only show up if your firewall is down or your anti-virus software is outdated as far as I recall.

OTHER TIPS

I ran into same issue while accessing sender email address for outlook mail item. To avoid 'security alert' do not create new Application object, instead use Globals.ThisAddIn.Application to create new mailitem.

string GetSenderEmail(Outlook.MailItem item)
    {
        string emailAddress = "";
        if (item.SenderEmailType == "EX")
        {
            Outlook.MailItem tempItem = (Outlook.MailItem)Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olMailItem);
            tempItem.To = item.SenderEmailAddress;
            emailAddress = tempItem.Recipients[1].AddressEntry.GetExchangeUser().PrimarySmtpAddress.Trim();

        }
        else
        {
            emailAddress = item.SenderEmailAddress.Trim();

        }

        return emailAddress;
    }

Try this

Tools-->Macro-->Security-->Programmatic Access

Then choose Never warn me about suspicious activity.

"But I am looking for a solution which don't require any third party COM library."

You won't find it. Kasper already pointed out the only solution that I know of. Redemption has been the only thing that has kept the Outlook plug-ins and code to work. I have done commercial Outlook add-ins for Franklin Covey. We explored a lot things, but Redemption was the only thing that got us over this hurdle.

If your application is not a Outlook plug in you can look at MAPI to read data from the inbox

We use Advanced Security for Outlook from Mapilab for this. It is free, also for commercial use, and still keeps Outlook safe (by only allowing access from approved applications). Just apposed to previously mentioned solutions that cost either money, or may compromise security.

You can disable the security pop-up using Outlook's Trust Center. Check here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top