none
Globals.ThisAddIn... Not Available in Solution. Am I Missing a Reference? RRS feed

  • Question

  • So, I'm trying to send Outlook message programmatically, and I see every where that the way to do it is to use Globals.ThisAddIn rather than App.CreateItem, e.g.

    this:
    
    Outlook.MailItem oMsg = (Outlook.MailItem)Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olMailItem)
    
    rather than:
    
    Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

    The Globals class is not available in my solution, and feel like I need to add a reference, but I cannot find anywhere what reference needs to be added. Thanks.

    Thursday, June 16, 2016 8:25 AM

Answers

  • To avoid those warnings you have to develop your solution as a trusted component - meaning an add-in.  See: https://msdn.microsoft.com/en-us/library/ff869289.aspx

    However, you may be able to bypass these warnings if anti-virus software is installed and/or you suppress the warnings - see: https://msdn.microsoft.com/en-us/library/bb226711.aspx


    Eric Legault (MVP: Outlook)
    Try MessageFiler for Outlook!

    • Marked as answer by Matt.Brown Sunday, June 26, 2016 3:36 PM
    Tuesday, June 21, 2016 8:14 PM

All replies

  • Hi Matt,

    >> I'm trying to send Outlook message programmatically

    What is your project type? Do you develop with Outlook add in or other project like Winform to send email? Globals.ThisAddIn is available in Outlook VSTO add-ins, you could refer Walkthrough: Creating Your First VSTO Add-In for Outlook. If you are not developing with Outlook VSTO add-ins, you could not use Globals.ThisAddIn, and you could use Outlook automation to send email, you could refer How to: Send an E-Mail Given the SMTP Address of an Account for how to send email in C# application.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, June 17, 2016 5:34 AM
  • Thanks for the reply. My project type is just a regular WPF application. I'm able to send an email using the second method you linked to, however Outlook pops up a couple of annoying security messages with every message sent programmatically, and I was attempting to avoid that. Thanks again, Matt.
    Friday, June 17, 2016 6:23 AM
  • To avoid those warnings you have to develop your solution as a trusted component - meaning an add-in.  See: https://msdn.microsoft.com/en-us/library/ff869289.aspx

    However, you may be able to bypass these warnings if anti-virus software is installed and/or you suppress the warnings - see: https://msdn.microsoft.com/en-us/library/bb226711.aspx


    Eric Legault (MVP: Outlook)
    Try MessageFiler for Outlook!

    • Marked as answer by Matt.Brown Sunday, June 26, 2016 3:36 PM
    Tuesday, June 21, 2016 8:14 PM
  • Hi Matt,

    >>however Outlook pops up a couple of annoying security messages with every message sent programmatically

    What is security messages details? If you send email from Outlook manually, will you get these message?

    It would be helpful if you could share us your simple code to send email.

    Best Regards,

    Edward 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, June 22, 2016 3:23 AM
  • Thanks for your help. The messages I get are first, paraphrased, "A program is attempt to access... allow for (select period of time), and the second, "Allow program to send an email on your behalf..." My code is below, and resides in a WPF project:

    Outlook.Application oApp = new Outlook.Application(); Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); oMsg.HTMLBody = "This email is just for your information. No action is required on your part.";

    int iPosition = (int)oMsg.Body.Length + 1;

    oMsg.Subject = "Payoff Quote Requested for " + item.Borrower + " (" + item.Account + ")"; Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients; Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("31361@something.com");

    oRecip.Resolve(); oMsg.Send();


    Thanks for your help. Matt




    • Edited by Matt.Brown Friday, June 24, 2016 8:00 AM
    Friday, June 24, 2016 7:56 AM
  • Hi Matt - see my earlier reply on how to circumvent those warnings.

    Eric Legault (MVP: Outlook)
    Try MessageFiler for Outlook!

    Friday, June 24, 2016 3:30 PM
  • Thanks, I'll work on that. Just out of curiosity, do you happen to know if my WPF would be able to call this trusted add-in in Outlook once it's been created?
    Friday, June 24, 2016 7:50 PM
  • It doesn't matter WHAT is creating an instance of the Outlook.Application object externally, as long as the trust relationship is established.

    But if you mean you want another application to call a method in your add-in, then it can be done if you expose the class/method as public and compile your assembly as COM aware (in the project settings).  E.g.:

    MyAddinNameSpaceName.ClassName myAddin = new MyAddinNameSpaceName.ClassName();

    myAddin.PublicMethodCall();


    Eric Legault (MVP: Outlook)
    Try MessageFiler for Outlook!

    Friday, June 24, 2016 7:54 PM
  • Okay. Thank you again.
    Sunday, June 26, 2016 3:36 PM
  • Hello Matt,

    The Globals class is available in VSTO based add-ins only. 

    Looks like you get a standard security prompt in Outlook. There is no need to develop an Outlook COM add-in for avoiding such popup windows. Instead, you can choose one of the following ways:

    1. Use a low-level API which doesn't trigger such prompts and on which Outlook is based on - Extended MAPI. Or you can choose any wrapper around that API such as Redemption. 

    2. Use group policy objects for deploying/configuring security settings on the machine.

    3. Use Security Manager for Microsoft Outlook in the code. It is programming tool (component) that allows you to bypass security settings andavoid security warnings, alerts or prompts in add-ins and applications that interact with Microsoft Outlook. I'd recommend using that component in standalone applications because it allows preserving the existing code and requires adding just few lines of code.

    Finally, you can read more about all these ways in the Outlook "Object Model Guard" Security Issues for Developers article. 


    [custom.development]

    Sunday, June 26, 2016 7:29 PM