none
How to get attachment event for an email when email is opened in reading pane? RRS feed

  • Question

  • Hello,

    I have to get notification when user adds attachments. I am able to do this by registering for MailItem Events when I get NewInspector events(https://docs.microsoft.com/en-us/office/vba/api/outlook.inspectors.newinspector).  

    However, when I try to reply/forward and reply/forward is configured to be opened in Reading Pane, then how should I registry for MailItem events? I am not getting New Inspector event.

    But, I am getting Explorer's selectionChange event when I right click on an email during which I am trying to register for MailItem events. This is not working, and I observed that Entry ID changes when email is opening in reading pane.

    When email is opened in new window, I don't have this problem because I get New Inspector event.

    Could you please help me here?

    Thanks in Advance!

    Bharath

    Monday, September 17, 2018 11:01 AM

Answers

  • Well, of course - attachments are not added to the email selected in the explorer - they are added to a new reply or forward emails that you can access in the Reply/ReplyAll/Forward events of the original message. That same new inline draft message can be accessed from Explorer.ActiveInlineResponse.

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

    Tuesday, September 25, 2018 3:21 PM
  • OOM does not know and does not care whether it is being used from C# or C++.

    Did you import the latest Outlook type library?


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

    Monday, October 8, 2018 3:57 PM

All replies

  • SelectionChange event should work. Are you setting up event sinks on all selected messages?

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

    Monday, September 17, 2018 3:47 PM
  • Hi Bharath,

    As Dmitry mentioned, have you tried setting up event sinks? if your issue is still exist then let us know about that, we will try to suggest you further to solve the issue.

    Best Regards,

    Simon


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Wednesday, September 19, 2018 12:19 PM
    Moderator
  • Hi Dmitry and Simon,

    Is  setting up event sinks mean to register for MailItem events for selected email? If yes, then I have tried that. In fact, entry ID of selected item changes. I think that;s the reason we don't get the notifications.

    Thanks,

    Regards,

    Bharath

    Wednesday, September 19, 2018 1:13 PM
  • Please show the relevant snippets of your code.

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

    Wednesday, September 19, 2018 2:10 PM
  • Hello Dmitry,

    Our plugin is developed in C++. 

    When I get selection event, I register for Mail item as below:

    void HandleMessageSelectionEvent()
    {
    IDispatch* pCtrl(NULL);
    CComQIPtr<Outlook::Selection> Olsel;
    m_pAddIn->m_pActiveExplorer->get_Selection(&Olsel);

    VARIANT IND;
    IND.vt = VT_I4;
    IND.intVal = 1;

    IDispatch* pMail(NULL);
    Olsel->Item(IND, &pMail);

    if (pMail)
    {      // DELETE PREVIOUS 
    if (m_pMailItemEventHandler)
    {
    m_pMailItemEventHandler->DetachFromSource();
    m_pMailItemEventHandler->Release();
    m_pMailItemEventHandler = NULL;
    }

    m_pMailItemEventHandler = new OLMailItemEventHandler(m_pOLAddIn);
    if (m_pMailItemEventHandler)
    {

                           //****ONLY TO DEBUG*****

    CComQIPtr<Outlook::_MailItem> mail;
    pMail->QueryInterface(IID__MailItem, (void**)&mail);

    if (mail != NULL)
    {
    CComBSTR sub;
    mail->get_EntryID(&sub);
    MessageBox(NULL, sub.m_str, L"Entry ID", NULL); // Show entry ID in message Box.
    }
                           //***ONLY TO DEBUG***

    m_pMailItemEventHandler->AddRef();
    m_pMailItemEventHandler->AttachingSource(pMail); // register for Mail Item Events
    }
    }
    }

    AttachingSource does following:

    STDMETHODIMP AttachingSource(IUnknown* pEventSource)
    {
    IConnectionPointContainer* pCPC = NULL;
    hr = pEventSource->QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC);
    if (SUCCEEDED(hr))
    {
    switch(m_EventType)
    {
                     ....
    case ExplorerEvent:
    hr = pCPC->FindConnectionPoint(Outlook::DIID_ExplorerEvents, &m_pConnectionPoint);
    break;
    case ExplorersEvent:
    hr = pCPC->FindConnectionPoint(Outlook::DIID_ExplorersEvents, &m_pConnectionPoint);
    break;
    case ItemAddEvent:
    hr = pCPC->FindConnectionPoint(Outlook::DIID_ItemsEvents, &m_pConnectionPoint);
    break;
                           .....
    case InspectorsEvent:
    hr = pCPC->FindConnectionPoint(DIID_InspectorsEvents, &m_pConnectionPoint);
    break;
    case MailItemEvent:
    hr = pCPC->FindConnectionPoint(Outlook::DIID_ItemEvents, &m_pConnectionPoint);
    break;
    }
    // Connection point found - advise of new event connection
    if (SUCCEEDED(hr))
    {
    hr = m_pConnectionPoint->Advise(static_cast<IDispatch*>(this), &m_dwCookie);
    if (FAILED(hr))
    {
    LOGERROR(_T("%s, 0x%08lx\r\n"), _T("ConnectionPoint->Advise() failed"), hr);
    }
    }

    Above code is working because I am getting Forward Email event for this Mail Item.

    But, I don't get Attachment add event. As per my investigation, Email Entry ID is changing when its opening in reading pane. But, forward event is trigger just before opening email in reading pane and it has old entry id.

    How did I get Entry ID for new email in reading pane?

    The answer is, I have registered for application's send event, and am displaying entry id when email is sent. Also, entry id is blank when I don't save the email before clicking on send button.

    Thanks,

    Regards,

    bharath

     

    Tuesday, September 25, 2018 10:08 AM
  • Well, of course - attachments are not added to the email selected in the explorer - they are added to a new reply or forward emails that you can access in the Reply/ReplyAll/Forward events of the original message. That same new inline draft message can be accessed from Explorer.ActiveInlineResponse.

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

    Tuesday, September 25, 2018 3:21 PM
  • Hi Bharath,

    Did you resolve your problem and any updates for this?  Please remember to mark the reply as answer if it helped. Please help us close the thread. Thanks for your understanding.

    Regards,

    Simon


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Monday, October 1, 2018 2:51 AM
    Moderator
  • Thanks a lot Dmitry and Simon. I haven't tried it yet due to my busy schedule. I will try it in 2-3 days and update you.

    Thanks,

    Bharath

    Monday, October 1, 2018 5:39 AM
  • Hi Dmitry,

    My plugin is in C++. Although I can find few references in internet for InlineActiveResponse, I am not able to find it in C++. Is it not available in C++?

    Thanks,

    Regards,

    Bharath

    Monday, October 8, 2018 3:54 PM
  • OOM does not know and does not care whether it is being used from C# or C++.

    Did you import the latest Outlook type library?


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

    Monday, October 8, 2018 3:57 PM
  • Yes! I was using older library and it worked now!!!

    Thanks a lot :).

    Tuesday, October 9, 2018 3:39 PM