Outlook Macro for checking the mail is sent to outside organization

santhoshbes

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Hi,

I need a help in macro for checking the outlook 2007 mail is sent to outside organization.

Example: If my organization is IBM, if a mail is sent to @yahoo.com, I need a popup saying, Whether do you really want to send the mail outside the organization.

I need a macro to be written in outlook

Please help!!!

Regards,

Santhosh Kumar
 

Amanda Barron

New Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
Hi, Santhosh

You can use the following macro to the task:

You can press Alt + F11 keys to enter VBA eidtor window, and then copy the following macro to the ThisOutlookSession project.

Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim objMail As Outlook.MailItem
    Dim objRecipients As Outlook.Recipients
    Dim i As Long
    Dim strRecipientAddress As String
    Dim strPrompt As String
    Dim nWarning As Integer
 
    If TypeOf Item Is MailItem Then
       Set objMail = Item
       Set objRecipients = objMail.Recipients
     
       For i = objRecipients.Count To 1 Step -1
           strRecipientAddress = objRecipients.Item(i).Address
           'Change "@ibm.com" to the email domain used by your own organization
           If InStr(LCase(strRecipientAddress), "@ibm.com") <= 0 Then
              Exit For
           Else
              Cancel = False
           End If
       Next i
     
       If InStr(LCase(strRecipientAddress), "@ibm.com") <= 0 Then
          strPrompt = "Are you sure to send this email to outside organizationy? "
          nWarning = MsgBox(strPrompt, vbYesNo + vbQuestion, "Confirm Email to Outside Organization")
          If nWarning = vbNo Then
             Cancel = True
          End If
       End If
    End If
End Sub
The subroutine will be triggered as soon as you click the "Send" button. It will check whether the receiver email address ends with "@ibm.com". If not, a warning will pop up, aksing if you confirm to send this email to the receiver. If you hit "yes", the email will be sent out. But if select "no", the email sending process will be canceled at once.

Hope that helps!

Good luck!

Amanda
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
If your company uses exchange server, internal recipients will use the x500 address - you can either check the recipients address for an @ sign (all external) or check for /ou, which is in the x500 address.

The macro example at Warn Before Sending Messages to the Wrong Email Address checks for messages being sent to both internal and external addresses but could easily be changed.
 
Top