none
How to create Outlook 2016 Add-In Such that a Pop-up occcurs after sending an email RRS feed

  • Question

  • I am trying to create an Outlook Add-In through Visual Studio with VBA that triggers a pop-up after the user presses the "Send" Button in an email. So far, I have gotten the pop-up to trigger in Outlook when the user clicks "New Email," but I want the popup to occur after pressing the send button, regardless if the email has text in it or not. The code I have so far is inserted below:

    Public Class ThisAddIn

    Private WithEvents inspectors As Outlook.Inspectors

    Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
        inspectors = Me.Application.Inspectors
    End Sub
    
    Private Sub inspectors_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector) Handles inspectors.NewInspector
        Dim mailItem As Outlook.MailItem = TryCast(Inspector.CurrentItem, Outlook.MailItem)
        If Not(mailItem is Nothing) Then
            MsgBox("test", vbOKCancel, "test")
        End If
    End Sub
    
    Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
    
    End Sub

    End Class


    • Edited by WQ6237 Thursday, June 28, 2018 7:02 PM
    Thursday, June 28, 2018 7:02 PM

Answers

  • Hello,

    You need to handle the ItemSend event of the Application class. It is fired whenever an Microsoft Outlook item is sent, either by the user through an Inspector (before the inspector is closed, but after the user clicks the Send button) or when the Send method for an Outlook item, such as MailItem , is used in a program.

    Public WithEvents myOlApp As Outlook.Application 
    Public Sub Initialize_handler() 
      Set myOlApp = Outlook.Application 
    End Sub 
    
    Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean) 
      Dim prompt As String 
      prompt = "Are you sure you want to send " &; Item.Subject &; "?" 
      If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo Then 
        Cancel = True 
      End If 
    End Sub


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    • Marked as answer by WQ6237 Monday, July 2, 2018 4:12 PM
    Thursday, June 28, 2018 7:20 PM
  • Hello WQ6237,

    The code Eugene share is VBA code and you are developing VSTO in VB.net. You need a bit adjustment for your project.

    See the sample demonstration.

    Best Regards,

    Terry


    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. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by WQ6237 Monday, July 2, 2018 4:12 PM
    Friday, June 29, 2018 3:20 AM

All replies

  • Hello,

    You need to handle the ItemSend event of the Application class. It is fired whenever an Microsoft Outlook item is sent, either by the user through an Inspector (before the inspector is closed, but after the user clicks the Send button) or when the Send method for an Outlook item, such as MailItem , is used in a program.

    Public WithEvents myOlApp As Outlook.Application 
    Public Sub Initialize_handler() 
      Set myOlApp = Outlook.Application 
    End Sub 
    
    Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean) 
      Dim prompt As String 
      prompt = "Are you sure you want to send " &; Item.Subject &; "?" 
      If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo Then 
        Cancel = True 
      End If 
    End Sub


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    • Marked as answer by WQ6237 Monday, July 2, 2018 4:12 PM
    Thursday, June 28, 2018 7:20 PM
  • Hi Eugene, this does not work when I run it in Visual Studio. I does not like the     

       myOlApp = Outlook.Application

    statement. Is there something I am missing?

    Thursday, June 28, 2018 11:16 PM
  • Hello WQ6237,

    The code Eugene share is VBA code and you are developing VSTO in VB.net. You need a bit adjustment for your project.

    See the sample demonstration.

    Best Regards,

    Terry


    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. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by WQ6237 Monday, July 2, 2018 4:12 PM
    Friday, June 29, 2018 3:20 AM