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

8

15

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.

Percaline answered 24/10, 2008 at 20:56 Comment(1)
U
10

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.

Unfold answered 24/10, 2008 at 21:14 Comment(3)
The unfortunate truth is that there were so many abuses of Outlook that Microsoft has it locked down and doesn't provide a way around it. I guess you could attempt replicate what Redemption does yourself, but I doubt the cost/benefit could beat the $200 license.Toms
indeed, $200 is nothing compared to the time you would need to come up with something like redemptionUnfold
I don't know about you guys, but I tried Kumar's answer down below (use oOutlookApp = Globals.ThisAddIn.Application, rather than creating a new Outlook object, it worked great for me, you should totally vote up his answer! :-))Bagwig
B
15

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;
    }
Bonniebonns answered 28/7, 2009 at 22:55 Comment(2)
If you are creating an actual outlook add-in (and not an external application that is tapping into Outlook), then this is the correct answer. In process addins do not trigger the warning dialog box as long as they only use the Application object that they were given by Outlook at startup (i.e. don't create a new Application object).Safford
Excellent answer! The vast majority of example add in code I found always created a new Application object. This solves SO many issues. :DMicrocline
U
10

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.

Unfold answered 24/10, 2008 at 21:14 Comment(3)
The unfortunate truth is that there were so many abuses of Outlook that Microsoft has it locked down and doesn't provide a way around it. I guess you could attempt replicate what Redemption does yourself, but I doubt the cost/benefit could beat the $200 license.Toms
indeed, $200 is nothing compared to the time you would need to come up with something like redemptionUnfold
I don't know about you guys, but I tried Kumar's answer down below (use oOutlookApp = Globals.ThisAddIn.Application, rather than creating a new Outlook object, it worked great for me, you should totally vote up his answer! :-))Bagwig
P
5

Try this

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

Then choose Never warn me about suspicious activity.

Prado answered 2/5, 2009 at 2:56 Comment(3)
I go for the kiss principle. I searched stackoverflow found this thread shall we call it. Read all about the fancy solutions. Read this one. Tried it and Dang what do you know. It worked. Thats the kind of simple solution I like. I was lucky that my client was using Outlook2007. Not all earlier Outlooks have this option.Gangue
All these options are disabled in my Outlook 2007. Is it because we have an Exchange Server? Is it possible to set it via group policies or something like that?Hussy
I don't see Programmatic Access in 2003Jacquerie
M
3

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

Maryettamaryjane answered 2/5, 2009 at 3:5 Comment(5)
Actually, I have been able to automatically "click" away this message so that the user doesn't notice it (2003 and 2007). In a commercial app.Matinee
@Danbystrom: How did you do that?Jacquerie
@Jeff: Fooling Outlook to believe that the OK button is being pressed by a human...Matinee
@danbystrom: Did you use something like SendKeys ~ ? Since the dialog in Outlook hangs my application, I can't see that working. I'm interested in what you didJacquerie
@Jeff: I don't want to give away too much: there's a reason the dialog is there. I just wanted to point out that the answer "You won't find it" is dead wrong. Don't stop looking. :-) Here are some clues: as for Outlook hanging you app, you need to start a background thread to do the work for you before starting to talk to Outlook. As for SendKeys - no, Outlook is smarter than that and will figure out what's going on. But there are other, common, well documented API functions that can be combined to do the trick.Matinee
L
1

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

Lakenyalaker answered 24/10, 2008 at 21:53 Comment(0)
J
1

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.

Jalapa answered 12/10, 2009 at 17:44 Comment(0)
C
1

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://mcmap.net/q/271171/-how-can-i-avoid-outlook-39-s-security-warning-when-sending-email-programmatically
  2. Install virus protection https://mcmap.net/q/271172/-how-can-i-register-my-python-program-with-outlook-to-send-mail-without-interference
  3. Redemption https://mcmap.net/q/271171/-how-can-i-avoid-outlook-39-s-security-warning-when-sending-email-programmatically or https://mcmap.net/q/271173/-getting-pop-up-message-while-accessing-email-though-vb-script (homepage: http://www.dimastr.com/redemption/home.htm )
  4. Update registry https://mcmap.net/q/271174/-what-causes-outlook-2007-to-prompt-quot-a-program-is-trying-to-send-an-e-mail-message-on-your-behalf-quot or https://mcmap.net/q/271175/-suppress-outlook-pop-up-allow-access
  5. Outlook security manager https://mcmap.net/q/271176/-stop-warning-of-outlook-when-sending-mail-from-python 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://mcmap.net/q/271177/-how-to-avoid-the-outlook-security-warning-for-email-automation
  8. vbSendMail https://mcmap.net/q/271178/-send-an-e-mail-through-a-macro-and-by-pass-security-settings
  9. ClickYes https://mcmap.net/q/271175/-suppress-outlook-pop-up-allow-access
  10. Automation Anywhere Outlook Metabot https://mcmap.net/q/271173/-getting-pop-up-message-while-accessing-email-though-vb-script
  11. A VB script to automatically click "Allow" button https://mcmap.net/q/271179/-sending-emails-from-excel-using-outlook-without-security-warning
  12. Use .Display() followed by pressing Enter to manually press the send button https://mcmap.net/q/271177/-how-to-avoid-the-outlook-security-warning-for-email-automation
  13. Use Windows Mail Client. https://mcmap.net/q/271174/-what-causes-outlook-2007-to-prompt-quot-a-program-is-trying-to-send-an-e-mail-message-on-your-behalf-quot
Chihuahua answered 20/2 at 0:30 Comment(0)
B
0

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

Baribaric answered 20/10, 2009 at 17:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.