How to Block from sending mail to public domain.

Status
Not open for further replies.

rancho

Member
Outlook version
Outlook 2010 64 bit
Email Account
hi,

I am new to forum, please accept my greetings.

Further, my team is using business mail id to communicate. Few days back I came to know that one of them have sent confidential files to his personal IDs (Public Domain) by mistake.

Please help me to block my team from sending any mails to any available public domain.
I am using OUTLOOK 2010.
 

Forum Admin

Senior Member
That is not really anything you can block in Outlook - the server usually handles it. Exchange server transport rules (including Office 365 exchange) can filter it. If you don't use exchange, you need to use your own smtp server and utility.

IRM (Individual rights management) would give you some control over the file but again, you need office 365 or an irm server.
 

rancho

Member
Outlook version
Outlook 2010 64 bit
Email Account
Hi,
I got resolution, we can put macro into it.

Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim recipients As Outlook.recipients
Dim recip As String
Dim i
 
'this code is encoded by Rochak Mehta
 
Set recipients = Item.recipients
For i = recipients.Count To 1 Step -1
recip$ = recipients.Item(i).Address
 
On Error Resume Next
Select Case LCase(recip)
 
Case "@gmail.com", "@ymail.com", "@yahoo.com", "@yahoo.in", "@yahoo.co.in", "@rediffmail.com"
 
Item.Send
 
Case Else
Prompt$ = "You are sending this to a Public Domain. Are you sure you want to send the Mail?"
 
If MsgBox(Prompt$, vbYesNo + vbCritical + vbMsgBoxSetForeground, "Check Address: By Rochak Mehta") = vbNo Then
Cancel = True
 
End If
End Select
 
Next
End Sub
 

rancho

Member
Outlook version
Outlook 2010 64 bit
Email Account
Hi Diane,

Thank you for the reply..

I have tried the suggestion, but its not working.
select Case instr(LCase(recip)) "Error doesn't letting me to close the last bracket".

Even my code lacking something somewhere as it prompts msg all the time whether I am sending it to a public domain(mentioned in the code) or business mail ID.

Could you please help me with this.

Thanks,
Rancho
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I'll test it, there might be a minor mistake that is easy to overlook. I use a similar macro so I know it should work.

Sent from my Venue 8 Pro 5830 using Tapatalk
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Btw, The code is configured to send to those domains and ask for all other domains.


Sent from my Venue 8 Pro 5830 using Tapatalk
 

Forum Admin

Senior Member
This works... instead of trying to use InStr, it uses an array and compares a string containing the recipients to the domains in the array. If you add domains, you'll need to raise the count for d - or let outlook calculate it using lbound and ubound.


Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim recipients As Outlook.recipients
Dim recip As Outlook.Recipient
Dim prompt As String
Dim domain As Variant
Dim strRecip As String
Dim i
Dim d As Long
'this code is encoded by Rochak Mehta
Set recipients = Item.recipients
  For i = recipients.Count To 1 Step -1
    Set recip = recipients.Item(i) '
    strRecip = recip & ";" & strRecip
Next
Debug.Print strRecip
On Error Resume Next

domain = Array("@gmail", "@ymail", "@yahoo", "@rediffmail")

For d = 0 To 3 'LBound(domain) To UBound(domain)
Debug.Print domain(d)
If InStr(LCase(strRecip), domain(d)) Then
    prompt$ = "You are sending this to a Public Domain. Are you sure you want to send the Mail?"
If MsgBox(prompt$, vbYesNo + vbCritical + vbMsgBoxSetForeground, "Check Address: By Rochak Mehta") = vbNo Then
Cancel = True
End If
Else
Item.Send
End If
Next d

End Sub
 
Status
Not open for further replies.
Top