none
A program is trying to access e-mail address information stored in Outlook ...

    Question

  • http://office.microsoft.com/en-us/outlook-help/a-program-is-trying-to-access-e-mail-addresses-you-have-stored-in-outlook-HA001112789.aspx

    I have a C# 4.0 application that uses outlook namespace for sending email.  I get that popup and after looking all over the web I was unable to find a simple solution to put in my code to prevent the user from getting that message.  This is an internal app so it should be able to send email.

    Microsoft.Office.Interop.Outlook.Application objOutlook = new Microsoft.Office.Interop.Outlook.ApplicationClass();
                Microsoft.Office.Interop.Outlook.NameSpace objNS = objOutlook.GetNamespace("MAPI");
                Microsoft.Office.Interop.Outlook.MailItem objMail = (Microsoft.Office.Interop.Outlook.MailItem)objOutlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);


    *** Please allow me to mark threads as answered and I will, Thank you ***

    Wednesday, February 27, 2013 2:29 PM

All replies

  • I cannot use any 3rd party tools and this needs to be done in code.

    *** Please allow me to mark threads as answered and I will, Thank you ***

    Wednesday, February 27, 2013 2:29 PM
  • if you are talking about security popup for user to allow app to touch sensitive outlook data then the only solution with custom app is to have up to date antyvir installed on machine.
    Wednesday, February 27, 2013 3:00 PM
  • We have Symantec 12.1.1101.401 (Release), RU1 MP1 installed.  Am I missing something else?

    *** Please allow me to mark threads as answered and I will, Thank you ***

    Wednesday, February 27, 2013 3:06 PM
  • Also, can't change any settings.  Everything where I work is pretty much locked down.

    *** Please allow me to mark threads as answered and I will, Thank you ***

    Wednesday, February 27, 2013 3:07 PM
  • What version of Outlook are you using? The latest versions of Outlook will nto display the prompt if the AV software is installed *and* is up to date.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Wednesday, February 27, 2013 4:49 PM
  • 2010 on a Win7 box

    *** Please allow me to mark threads as answered and I will, Thank you ***

    Wednesday, February 27, 2013 6:07 PM
  • Make sure the AV definitions are up to date.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Wednesday, February 27, 2013 6:14 PM
  • I'm sure they are as I have no control over doing a live update. Any thought on what I can do in my code to get around this?  Turn it off, do the email, then turn it back on kind of thing?

    *** Please allow me to mark threads as answered and I will, Thank you ***

    Wednesday, February 27, 2013 6:20 PM
  • check in control panel in proper applet (i do not remember its name) if windows actually think that you have antyvir installed and up to date. This is the most important part (what windows thinks)
    Wednesday, February 27, 2013 6:32 PM
  • It is from what I can tell.  After making some changes to the send mail piece i now get a nasty error (framework 4.0 and win7)

    Unable to cast COM object of type 'System__ComObject' to interface type 'Micorosoft.Office.Interop.Outlook.MailItem . . .

    Works fine in xp box with 2003 using the 14.0.0.0

    Microsoft.Office.Interop.Outlook


    *** Please allow me to mark threads as answered and I will, Thank you ***

    Wednesday, February 27, 2013 8:51 PM
  • apparently object that you got is not a mailitem. fix your code. You can show us offending piece of code, maybe we will spot the bug.
    Thursday, February 28, 2013 4:57 AM
  • Outlook.Application objApp = new Outlook.Application();

    //this line below is where it crashes Outlook.MailItem objMail = (Outlook.MailItem)objApp.CreateItem(Outlook.OlItemType.olMailItem); objApp.CreateItem(Outlook.OlItemType.olMailItem); objMail.Subject = "ScreenShot " + DateTime.Now.ToString(); objMail.Body = "ScreenShot " + ItemID + "\nDate: " + DateTime.Now.ToString() + "\nDescription: " + Description + "\n\n"; foreach (FileInfo fi in rgFiles) { String sSource = SavePath + fi.Name; String sDisplayName = fi.Name; int iPosition = (int)objMail.Body.Length + 1; int iAttachType = (int)Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue; Microsoft.Office.Interop.Outlook.Attachment oAttach = objMail.Attachments.Add(sSource, iAttachType, iPosition, sDisplayName); } try { objMail.Display(false); } catch (System.Runtime.InteropServices.COMException ex) { MessageBox.Show(ex.Message, "ScreenShot"); e; } catch (System.Exception ex) { MessageBox.Show(ex.Message, "ScreenShot"); }



    *** Please allow me to mark threads as answered and I will, Thank you ***


    • Edited by ski_freak Thursday, February 28, 2013 12:55 PM
    Thursday, February 28, 2013 12:48 PM
  • right after

    Outlook.Application objApp = new Outlook.Application();

    add

    var session = objApp.GetNamespace("MAPI")

    Thursday, February 28, 2013 1:24 PM
  • I added it and still get the same error.  Don't I have to USE the session some where?

    *** Please allow me to mark threads as answered and I will, Thank you ***

    Thursday, February 28, 2013 1:48 PM
  • if you start outlook yourself and attach to it using Marshal.GetActiveObject("Outlook.Application") do you still get that error on CreateItem?
    Thursday, February 28, 2013 2:44 PM
  • Not sure what you are asking.  I have code that tests to see if outlook is running and it is bypassing that code.  Outlook 2010 is up and running.  I am installing each attempt to the win 7 vm via Publish.  I on revision 20 now.  I have interop ver 14 and confirmed that in the error as well.  Funny thing is that it works fine on XP/2003! Doesnt matter which interop i use too.

    *** Please allow me to mark threads as answered and I will, Thank you ***

    Thursday, February 28, 2013 2:53 PM
  • I put this in at the top of the code and now i get a different error

    object objOL = Marshal.GetActiveObject("Outlook.Application");


    *** Please allow me to mark threads as answered and I will, Thank you ***

    Thursday, February 28, 2013 2:54 PM
  • What is the version of Outlook on the problematic machine?

    What was the version of Outlook used to create the interop dll?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Thursday, February 28, 2013 3:11 PM
  • Outlook version 2010 on a win 7 Virtual Machine.  I am not sure about your 2nd question but the version of

    Microsoft.Office.Interop.Outlook is 14.0.0.0

    Dies on this line:

    Microsoft.Office.Interop.Outlook.MailItem objMail = (Microsoft.Office.Interop.Outlook.MailItem)objApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);


    *** Please allow me to mark threads as answered and I will, Thank you ***

    Thursday, February 28, 2013 3:16 PM
  • I meant on the machine where you added Outlook to your program references, what was the version of Outlook?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Thursday, February 28, 2013 3:19 PM
  • ahh I think you mean my DEV VM.  It is XP/Office 2003.  Do I need to develop on a win7 box with office 2010?

    *** Please allow me to mark threads as answered and I will, Thank you ***

    Thursday, February 28, 2013 3:26 PM
  • No, Outlook is backward compatible, 2003 interop should work just fine with Outlook 2010.

    Th rule of thumb is to develop with the least supported version, so you did everything right.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Thursday, February 28, 2013 5:54 PM
  • Any other suggestions?  I am getting a Win7 true box shortly and will try there.  We have only tried our tests in VM's.


    *** Please allow me to mark threads as answered and I will, Thank you ***

    Thursday, February 28, 2013 7:47 PM
  • I am getting a Win7 true box shortly and will try there.

    Any luck with your latest experiment?


    with regards, Yuri

    Thursday, March 07, 2013 7:23 AM