What is the best way to check for multiple black-list email addresses before sending?
I have several email addresses I am not allowed to send information to as part of a project. I want Outlook to check for any of the black-list email addresses and notify me if they are included before sending. Below is the code I found to modify
For example, my black-list includes: "bad@address.com", "worst@address.com", "evil@address.com"
What is the best way to put these addresses into the code below, would be good for it to be in a way that allows for changing the addresses in the black-list easily?
So here is the latest version of my code with your suggestions. Unfortunately it lets me send the emails to the addresses on the Checklist. Any suggestions?
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim Recipients As Outlook.Recipients
Dim recip As Outlook.Recipient
Dim i
Dim prompt As String
On Error Resume Next
' use lower case for the address
' LCase converts all addresses in the To field to lower case
Checklist = "bad@address.com" & _
"worst@address.com" & _
"evil@address.com" '// , _ and so on
Set Recipients = Item.Recipients
For i = Recipients.Count To 1 Step -1
Set recip = Recipients.Item(i)
If InStr(LCase(recip), LCase(Checklist)) Then
prompt$ = "You sending this to this to " & Item.To & ". Are you sure you want to send it?"
If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Address") = vbNo Then
Cancel = True
End If
End If
Next i
End Sub
See Question&Answers more detail:os