none
Need assist finding MailItem.Forward Event in Outlook 2013 Managed Interop RRS feed

  • Question

  • The MailItem.Forward Event is missing and I need help figuring out why.  This is the Event I want to use https://msdn.microsoft.com/EN-US/library/office/ff862702.aspx

    What I need to do is conditionally cancel a send when a piece of mail is being forwarded, if it is being replied to or if it is a new piece. I have added an event handler to Application.ItemSend and that works. But I need need help determining if the mail is being forwarded, replied to or is new. How can I do this?

    My assembly references are:

    using

    System;


    using

    System.Collections.Generic;


    using

    System.Linq;


    using

    System.Text;


    using

    System.Xml.Linq;


    using

    Outlook = Microsoft.Office.Interop.Outlook;


    using

    Office = Microsoft.Office.Core;


    using

    System.Windows.Forms;


    using

    System.Runtime.InteropServices;

    Microsoft Visual Studio Professional 2013
    Version 12.0.31101.00 Update 4
    Microsoft .NET Framework
    Version 4.5.51650

    Installed Version: Professional

    LightSwitch for Visual Studio 2013   06177-004-0444002-02170
    Microsoft LightSwitch for Visual Studio 2013

    Team Explorer for Visual Studio 2013   06177-004-0444002-02170
    Microsoft Team Explorer for Visual Studio 2013

    Visual Basic 2013   06177-004-0444002-02170
    Microsoft Visual Basic 2013

    Visual C# 2013   06177-004-0444002-02170
    Microsoft Visual C# 2013

    Visual C++ 2013   06177-004-0444002-02170
    Microsoft Visual C++ 2013

    Visual F# 2013   06177-004-0444002-02170
    Microsoft Visual F# 2013

    Visual Studio 2013 Code Analysis Spell Checker   06177-004-0444002-02170
    Microsoft® Visual Studio® 2013 Code Analysis Spell Checker

    Portions of International CorrectSpell™ spelling correction system © 1993 by Lernout & Hauspie Speech Products N.V. All rights reserved.

    The American Heritage® Dictionary of the English Language, Third Edition Copyright © 1992 Houghton Mifflin Company. Electronic version licensed from Lernout & Hauspie Speech Products N.V. All rights reserved.

    Windows Phone SDK 8.0 - ENU   06177-004-0444002-02170
    Windows Phone SDK 8.0 - ENU

    Application Insights Tools for Visual Studio Package   1.0
    Application Insights Tools for Visual Studio

    ASP.NET and Web Tools   12.4.51016.0
    Microsoft Web Developer Tools contains the following components:
    Support for creating and opening ASP.NET web projects
    Browser Link: A communication channel between Visual Studio and browsers
    Editor extensions for HTML, CSS, and JavaScript
    Page Inspector: Inspection tool for ASP.NET web projects
    Scaffolding: A framework for building and running code generators
    Server Explorer extensions for Microsoft Azure Websites
    Web publishing: Extensions for publishing ASP.NET web projects to hosting providers, on-premises servers, or Microsoft Azure

    ASP.NET Web Frameworks and Tools 2012.2   4.1.21001.0
    For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

    ASP.NET Web Frameworks and Tools 2013   5.2.21010.0
    For additional information, visit http://www.asp.net/

    Common Azure Tools   1.3
    Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

    Microsoft Azure Mobile Services Tools   1.3
    Microsoft Azure Mobile Services Tools

    NuGet Package Manager   2.8.50926.663
    NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

    Office Developer Tools for Visual Studio 2013 ENU   12.0.30626
    Microsoft Office Developer Tools for Visual Studio 2013 ENU

    PowerShell Tools   1.3
    Provides file classification services using PowerShell

    PreEmptive Analytics Visualizer   1.2
    Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

    SQL Server Data Tools   12.0.41012.0
    Microsoft SQL Server Data Tools

    Windows Phone 8.1 SDK Integration   1.0
    This package integrates the tools for the Windows Phone 8.1 SDK into the menus and controls of Visual Studio.

    Workflow Manager Tools 1.0   1.0
    This package contains the necessary Visual Studio integration components for Workflow Manager.

    Thursday, September 17, 2015 10:02 PM

Answers

  • David,

    There is no need to copy/paste the text from the link I mentioned previously.

    Moreover, to get the event fired you need to declare the source object at the global scope. Or it will be swiped by the garbage collector. 

    Outlook.MailItem mailItem = null;
    
    public void Startup()
    {  mailItem=Application.CreateItem(Outlook.OlItemType.olMailItem);
    
         ((Outlook.ItemEvents_10_Event)mailItem).Forward += mailItem_Forward;
    
    }
    
    

    • Marked as answer by Joel_Z Friday, September 18, 2015 3:47 PM
    Friday, September 18, 2015 8:35 AM

All replies

  • Hello Joel,

    You need to cast the mail item object to the ItemEvents_10_Event interface and then subscribe to the Forward event. Don't forget to declare the source object at the global to prevent it from swiping by the GC.

    Friday, September 18, 2015 5:07 AM
  • >>>The MailItem.Forward Event is missing and I need help figuring out why.

    ItemEvents_10_Event interface is a .NET interface created when processing a COM coclass that is required by managed code for interoperability with the corresponding COM object. This interface implements all events of earlier interfaces and any additional new events. Use this interface only when the event you want to use shares the same name as a method of the COM object; in this case, cast to this interface to connect to the event, and cast to the primary interface to call the method. Otherwise, use the .NET interface that is derived from the COM coclass to access methods, properties, and events of the COM object.

    So you could refer to below code:

    static void Main(string[] args)
    {
    
         Outlook.Application app = new Outlook.Application();
    
         Outlook.MailItem mailItem=app.CreateItem(Outlook.OlItemType.olMailItem);
    
         ((Outlook.ItemEvents_10_Event)mailItem).Forward += mailItem_Forward;
    
    }
    
    
    static void mailItem_Forward(object Forward, ref bool Cancel)
    
    {
    
         //your logic code
    
    }
    

    For more information, click here to refer about ItemEvents_10_Event interface

    Friday, September 18, 2015 8:24 AM
  • David,

    There is no need to copy/paste the text from the link I mentioned previously.

    Moreover, to get the event fired you need to declare the source object at the global scope. Or it will be swiped by the garbage collector. 

    Outlook.MailItem mailItem = null;
    
    public void Startup()
    {  mailItem=Application.CreateItem(Outlook.OlItemType.olMailItem);
    
         ((Outlook.ItemEvents_10_Event)mailItem).Forward += mailItem_Forward;
    
    }
    
    

    • Marked as answer by Joel_Z Friday, September 18, 2015 3:47 PM
    Friday, September 18, 2015 8:35 AM
  • it's better
    static void Main(string[] args)
    {
    
        ((ItemEvents_10_Event)Application.CreateItem(OlItemType.olMailItem)).Forward += Application_ItemForward;
    
    }
    
    
    static void Application_ItemForward(object Forward, ref bool Cancel)
    
    {
    
         //your logic code
    
    }

    Friday, January 22, 2016 8:37 PM
  • You will not get the event fired more than one time. The source object will be swiped by the garbage collector and no more events will be fired. With this in mind the source object should be defined at the global scope.
    Friday, January 22, 2016 11:16 PM