Outlook Macro for checking the mail is sent to outside organization

Status
Not open for further replies.

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.
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
M Outlook macro to automate search and forward process Outlook VBA and Custom Forms 6
R Macro Schedule every day in Outlook Using Outlook 0
L Moving emails with similar subject and find the timings between the emails using outlook VBA macro Outlook VBA and Custom Forms 1
N How can I increase/faster outlook VBA Macro Speed ? Using Outlook 2
A Outlook macro to create search folder with mail categories as criteria Outlook VBA and Custom Forms 3
V Outlook Macro to show Flagged messages Outlook VBA and Custom Forms 2
J Help Please!!! Outlook 2016 - VBA Macro for replying with attachment in meeting invite Outlook VBA and Custom Forms 9
S Macro using .SendUsingAccount only works the first time, after starting Outlook Outlook VBA and Custom Forms 4
M Slow VBA macro in Outlook Outlook VBA and Custom Forms 5
A Forward Outlook Email by Filtering using Macro Rule Outlook VBA and Custom Forms 44
Tanja Östrand Outlook 2016 - Create Macro button to add text in Subject Outlook VBA and Custom Forms 1
D Outlook macro with today's date in subject and paste clipboard in body Outlook VBA and Custom Forms 1
C Outlook Subject Line Macro Outlook VBA and Custom Forms 0
D Macro sending outlook template from Excel list Outlook VBA and Custom Forms 6
P Macro to attach a file in a shared Outlook draft folder Outlook VBA and Custom Forms 2
R Macro to check file name with outlook address book Outlook VBA and Custom Forms 0
Diane Poremsky Use a macro to copy data in Outlook email to Excel workbook New Slipstick.com Articles 0
W macro to export outlook emails to excel Outlook VBA and Custom Forms 6
J Outlook Macro to Update Sharepoint Excel File Using Outlook 1
Patrick van Berkel Best way to share (and keep up-to-date) Macro's in Outlook 2010 Outlook VBA and Custom Forms 6
C Newbie needs help with Outlook Macro Outlook VBA and Custom Forms 3
L Outlook 2007 - Macro Re Search Using Outlook 16
L Outlook 2007 Macro to Contact From a Field Using Outlook 3
A newb outlook macro help Outlook VBA and Custom Forms 1
Diane Poremsky Macro to Bulk Import Contacts and vCards into Outlook New Slipstick.com Articles 0
S Outlook 7 VBA macro for multiple filing Outlook VBA and Custom Forms 1
S Macro in an excel for outlook. Outlook VBA and Custom Forms 2
A Outlook Macro Causing Excel Error Outlook VBA and Custom Forms 0
Diane Poremsky Use a macro to copy data in Outlook email to Excel workbook New Slipstick.com Articles 0
S Outlook Macro Reply to a message Outlook VBA and Custom Forms 1
Diane Poremsky Macro to Bulk Import vCards into Outlook New Slipstick.com Articles 0
M Outlook VBA Macro that could retrieve/display the (From, Subject, Date Received) Outlook VBA and Custom Forms 2
Philip Rose Recreating a WORD Editing Macro to use in Outlook VBA Outlook VBA and Custom Forms 4
A Macro to Copy Data from Outlook to Excel Spreadsheet Using Outlook 2
P Outlook Macro sends information to Excel Using Outlook 1
P Outlook Macro keeps running for the same messagage Using Outlook 2
B Looking for Outlook 2013 update for Send Drafts Macro Using Outlook 4
J VBS Script (macro) for word to open Outlook template. Outlook VBA and Custom Forms 2
S Macro for Reply All in 2013 Outlook Outlook VBA and Custom Forms 10
L Outlook 2007 Macro Save Contact Using Outlook 10
Aussie Looking for Outlook macro to Copy Recipient Names into Email Body Outlook VBA and Custom Forms 3
H Outlook Macro Using Outlook 1
L Outlook 2007 Macro Reply to E-mail Using Outlook 16
L Outlook 2007 Macro Search Contacts Using Outlook 9
L Outlook 2007 Macro to LinkedIn Using Outlook 3
L Outlook 2007 Macro Open Contact Folder Using Outlook 7
H Macro to file Outlook email by sender's email address Using Outlook 11
L Outlook Macro for flagging messages Using Outlook 0
B Outlook vba macro Using Outlook 1
S Outlook macro to move replied / forwarded emails to a seperate folder Using Outlook 1
Similar threads


















































Top