none
Event Outlook.Items.ItemAdd is not fired when sending PDF from Abode Reader. When sending from MS Office apps - all OK. RRS feed

  • Question

  • Hi.

    I have small Outlook AddIn, which main purpose is to Send email programmatically and save it from Sent folder to another place. Nothing complicated, but there is one problem with Adobe Acrobat Reader: if PDF document is Sent with email from Adobe Reader, event ItemAdd is not fired, when item goes to Sent folder in Outlook. When I send documents with email from MS Office apps, everything works super!

    I wish it would be Adobe issue :), because even without AddIns this feature is not very stable :(.

    Does anyone know anything what can help to resolve it ? 

    Thanks :) 

    Here is my test code:

     Private WithEvents _SaveFolderItems As Outlook.Items

        Private Sub _SaveFolderItems_ItemAdd(ByVal item As Object) Handles _SaveFolderItems.ItemAdd
            MsgBox("Email has been added to Sent folder.")
        End Sub

        Private Sub AdxRibbonButton1_OnClick(sender As Object, control As IRibbonControl, pressed As Boolean) Handles AdxRibbonButton1.OnClick
            Dim CurrentInspector As Outlook.Inspector
            Dim Inspectors As Outlook.Inspectors

            Try
                Inspectors = OutlookApp.Inspectors
                If Inspectors.Count > 0 Then
                    CurrentInspector = TryCast(OutlookApp.ActiveInspector, Outlook.Inspector)

                    Dim MailItem As Outlook.MailItem = Nothing
                    Try
                        MailItem = CurrentInspector.CurrentItem
                        _SaveFolderItems = If(MailItem.SaveSentMessageFolder IsNot Nothing, MailItem.SaveSentMessageFolder.Items, Nothing)

                        MailItem.Send()
                    Catch ex As Exception
                        MsgBox(ex.ToString)
                    Finally
                        If MailItem IsNot Nothing Then
                            Marshal.ReleaseComObject(MailItem)
                        End If
                    End Try
                End If
            Finally
                Try
                    If Inspectors IsNot Nothing Then Marshal.ReleaseComObject(Inspectors)
                Catch
                End Try
                Try
                    If CurrentInspector IsNot Nothing Then Marshal.ReleaseComObject(CurrentInspector)
                Catch
                End Try
                GC.WaitForPendingFinalizers()
            End Try
        End Sub


    Thursday, August 3, 2017 10:57 AM

All replies

  • Hi Sergey Chizh,

    It seems you initialize the _SaveFolderItems in an button click event.

    When you send the PDF from Adobe Reader, is Outlook openning and has the button been clicked?

    I don't have Adobe Reader, so I used Excel to send a mail for testing. After opening the Outlook and using the button to send a mail, then I used the excel to send a mail, the event was fired. I suggest you do such a test with Adobe Reader.

    If it could works for you, I suggest you initialize the _SaveFolderItems in Start_Up event to make sure the _SaveFolderItems has been initialized and the event could fire.

    Here is the example.

        Private WithEvents _SaveFolderItems As Outlook.Items
    
        Private Sub ThisAddIn_Startup() Handles Me.Startup
            _SaveFolderItems = Globals.ThisAddIn.Application.GetNamespace("MAPI").
              GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderSentMail).Items
        End Sub
    
        Private Sub _SaveFolderItems_ItemAdd(ByVal item As Object) Handles _SaveFolderItems.ItemAdd
            MsgBox("Email has been added to Sent folder.")
        End Sub

    Best Regards,

    Terry

    Friday, August 4, 2017 6:56 AM
  • Hi Terry,

    Thank you, your suggesting helped. I moved initialization to StartUp event and it worked :) 

    Still strange why it didn't work in Acrobat before (I clicked the button), but worked from MS Office apps.

    Anyways, thanks!

    Friday, August 4, 2017 8:33 AM
  • Hi Sergey Chizh,

    I'm glad to hear that you have solved the issue. I suggest you mark the helpful reply as
    answer to close this thread. Thanks for understanding.

    Best Regards,

    Terry


    Friday, August 4, 2017 10:40 AM