Hey guys, wondering if anybody can provide any help with an Outlook VBA task that I have.
I'm using Outlook 2007 but need the code to work on 2010 also. What I want to acheive is code that runs when an email is sent. If it is sent from a specific shared mailbox I want to check the body of the email for a particular sentence. If it is true, send the item, if it is not true, I want to prompt the user with a msgbox saying "Are you sure you want to send it from this email address?"
To give you an example of the code I have, I'll post it below. The issue with this code is that it displays the prompt no matter what the .sentOnBehalfOf Email Address is. I have this code pasted in 'ThisOutlookSession'
Option Explicit Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) If Item.SentOnBehalfOfName = "[email protected]" Then Else If InStr(Item.Body, "Text to find in email body") > 0 Then Else If MsgBox("Are you sure you want to sent this email from [email protected]?", vbOKCancel) <> vbOK Then Cancel = True End If End If End If End Sub