Call method when e-mail sent from Outlook?
There's a VBA class called MailItemClass
that has an event for when an e-mail has been sent in Outloo开发者_如何学编程k. I can't find this for VB.NET. I've looked through the documentation but I just can't find it in the MAPI
.
(Can I call VBA from VB.NET?)
Are you making an Outlook Add-in? There's an event called Application.ItemSend that is raised before an item is sent. I just launched VS2010, created a new project of type Outlook 2007 Add-in that contains just the below code and my Application_ItemSend
fired as expected when I clicked Send from Outlook.
Public Class ThisAddIn
Private Sub ThisAddIn_Startup() Handles Me.Startup
End Sub
Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
End Sub
Private Sub Application_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean) Handles Application.ItemSend
System.Windows.Forms.MessageBox.Show("Hi")
End Sub
End Class
EDIT
If you're making a WinForms app that you use the same method but you "see" it a little differently. What can be a little confusing is that the event is raised at the application level and not from the mail item itself.
Public Class Form1
''//Holds a reference to our mail application
Private WithEvents OA As Microsoft.Office.Interop.Outlook.Application
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
''//Either launches Outlook or snaps to the current running one
OA = New Microsoft.Office.Interop.Outlook.Application()
End Sub
Private Sub OA_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean) Handles OA.ItemSend
MessageBox.Show("Hello")
End Sub
End Class
Both VBA and VB.NET use the "Outlook Object Model". It is odd that the send event is omitted. However, you still have this event.
I'm not much of VB guy, but as MAPI is oriented to C++, using it from VB.net doesn't sound very streamlined, but the MailItem will roughly correspond to LPMESSAGE. The various outlook addin frameworks have pretty good notification systems in place. If you need go with MAPI alone, check MAPI events, ...but it's not easy.
精彩评论