Naga
Naga

Reputation: 327

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

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.

Upvotes: 15

Views: 41386

Answers (8)

user202729
user202729

Reputation: 3955

Another solution that works for me. Taken from https://learn.microsoft.com/en-us/archive/msdn-technet-forums/64c14bd3-0e7f-4ba9-b2bd-26cf62ce5883 .

This is similar to the answer above, but would work in case the option is grayed out.

  • Go to "File → Options → Trust Center → Trust Center Settings → Programmatic access".
  • Choose "Never warn me about suspicious activity".
  • If the option is grayed out, do the following:
    • Exit Outlook.
    • Run Outlook as administrator.
    • Repeat the above again.

Note: after an Outlook update, the setting might be reset. So consider double-checking the option if you find it not work.


Other methods are listed below.

  1. Other methods to bypass Outlook (MAPI, SMTP, etc.): Refer to Sending email from Command-line via outlook without having to click send or https://stackoverflow.com/a/1052763/5267751
  2. Install virus protection https://stackoverflow.com/a/22825351/5267751
  3. Redemption https://stackoverflow.com/a/1052649/5267751 or https://stackoverflow.com/a/58750475/5267751 (homepage: http://www.dimastr.com/redemption/home.htm )
  4. Update registry https://stackoverflow.com/a/54719118/5267751 or https://stackoverflow.com/a/36305470/5267751
  5. Outlook security manager https://stackoverflow.com/a/27962584/5267751 https://www.add-in-express.com/outlook-security/
  6. https://web.archive.org/web/20130812212513/http://www.outlookcode.com/article.aspx?ID=52
  7. Digital signature https://stackoverflow.com/a/12062741/5267751
  8. vbSendMail https://stackoverflow.com/a/58855585/5267751
  9. ClickYes https://stackoverflow.com/a/36302692/5267751
  10. Automation Anywhere Outlook Metabot https://stackoverflow.com/a/58761937/5267751
  11. A VB script to automatically click "Allow" button https://stackoverflow.com/a/29921482/5267751
  12. Use .Display() followed by pressing Enter to manually press the send button https://stackoverflow.com/a/25345147/5267751
  13. Use Windows Mail Client. https://stackoverflow.com/a/33247285/5267751

Upvotes: 1

Sandeep Aparajit
Sandeep Aparajit

Reputation: 1

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

Upvotes: 0

Jorrit Reedijk
Jorrit Reedijk

Reputation: 608

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.

Upvotes: 1

kumar
kumar

Reputation:

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;
    }

Upvotes: 15

Hector Sosa Jr
Hector Sosa Jr

Reputation: 4250

"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.

Upvotes: 3

Kunal Ranglani
Kunal Ranglani

Reputation:

Try this

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

Then choose Never warn me about suspicious activity.

Upvotes: 5

Kasper
Kasper

Reputation: 1708

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.

Upvotes: 10

Aaron Fischer
Aaron Fischer

Reputation: 21211

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

Upvotes: 1

Related Questions