Currently my code checks the email (on the Item_Send Event) to see if it has an attachment and then gives a conditional Form to Encrypt and Send, Send Un-encrypted, or Cancel Send. It also searches for SSN's in the body giving the user the same Form popup. All works as advertised unless the user has two email windows/instances open at the same time. For example if email#1 has an attachment and email#2 is sitting in the background, if I were to try and send email#1 and opt to Cancel Send it goes back to email#1 without sending (as advertised), however, when you go back to email#2 and try to send (that has nothing to do with email#1) it will not send either. I'll show the code below, but I use the "Cancel=True" command to stop the email, but this stops the send operation and the inspector is left open, thus not letting me send any emails that may have been open at that time. Is there any ideas around this? How can I have this Item_Send event only handle the CURRENT Outlook.MailItem instance and not another that may be open at the same time. Thanks! I left alot out of the code, this is just part of the problem I'm having. SSNBtnPress=3 for Cancel=True
Public Sub Application_ItemSend(ByVal Item As Object, _
ByRef Cancel As Boolean) Handles Application.ItemSend
Dim mailItem As Outlook.MailItem = TryCast(Item, Outlook.MailItem)
If mailItem IsNot Nothing Then
frm1.ShowDialog()
If (SSNbtnPress = 1) Then
mailItem.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/x-PII", "Encryptclicked")
If RegexObj1.IsMatch(mailItem.Body) Then
mailItem.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x6E010003", 3)
Cancel = False
ElseIf RegexObj1.IsMatch(mailItem.Subject) Then
mailItem.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x6E010003", 3)
Cancel = False
Else
mailItem.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x6E010003", 3)
Dim addToBody As String = "Test" + vbNewLine + vbNewLine + mailItem.Body
Dim addtoSubject As String = "Test " + mailItem.Subject
mailItem.Subject = addtoSubject
mailItem.Body = addToBody
Cancel = False
End If
End If
End If
If (SSNbtnPress = 2) Then
mailItem.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/x-PII", "SUclicked")
mailItem.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x6E010003", 2)
Cancel = False
Exit Sub
ElseIf (SSNbtnPress = 3) Then
mailItem.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x6E010003", 2)
Cancel = True
Exit Sub
End If
End Sub
End Class
If all you desire is to check whether the item being sent corresponds to the item open at the time of sending, you need to look into the ActiveInspector.
You can access the active inspector through your reference variable to the Outlook application, and you can access the Application variable through the item itself.
Once referencing the ActiveInspector, you can get its CurrentItem and compare this to the item being sent, e.g.
Dim isItemBeingSentCurrent As Boolean = mailItem.Application.ActiveInspector.CurrentItem Is mailItem