Reputation: 5860
I am trying to catch the event when the user clicks on the New Mail button for writing a new mail. Any suggestions on what that is called? I have been looking everywhere for it but everything is directly me to the read mail option.
Upvotes: 0
Views: 2425
Reputation: 49397
In some cases accessing the MailItem in the NewInspector event is too early. I.e. you will not get a valid MailItem object. That's why I'd recommend waiting for the first Activate event of the Inspector class.
You may find the Developing an Inspector Wrapper for Outlook 2010 article in MSDN helpful.
Upvotes: 1
Reputation: 4512
When you create a new Outlook project Visual Studio creates the FirstOutlookAddIn
project and opens the ThisAddIn
code file in the editor.
Declare a field named inspectors in the ThisAddIn
class
Private WithEvents inspectors As Outlook.Inspectors
Replace the ThisAddIn_Startup
method with the following code
Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
inspectors = Me.Application.Inspectors
End Sub
In the ThisAddIn
code file, add the following code to the ThisAddIn
class
This code defines an event handler for the NewInspector
event.
When the user creates a new mail message, this event handler adds text to the subject line and body of the message.
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
If mailItem.EntryID Is Nothing Then
mailItem.Subject = "This text was added by using code"
mailItem.Body = "This text was added by using code"
End If
End If
End Sub
Upvotes: 4