How can I filter recipients in To: field in Outlook using VBA

By jbondsr ·
Hi guys.

I have this code from BlueDevil fan and it works great. It counts the number of recipients in the To and Cc fields and denies sending the email if the parameters are exceeded. What I need to add is someway to ignore/not count any addresses in the fields that are internal addresses or are distribution lists.

Here the code I have so far:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim olkRecipient As Outlook.Recipient, _
intTo As Integer, _
intCC As Integer, _
intBCC As Integer
If Item.Class = olMail Then
For Each olkRecipient In Item.Recipients
Select Case olkRecipient.Type
Case olTo
intTo = intTo + 1
Case olCC
intCC = intCC + 1
Case olBCC
intBCC = intBCC + 1
End Select
If (intTo > 1) Or (intCC > 1) Then
MsgBox "You are only allowed 1 address in the To and CC lines.", vbCritical + vbOKOnly, "Message Not Sent"
Cancel = True
End If
End If
Set olkRecipients = Nothing
End Sub

Thanks in advance

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Share your knowledge

Related Discussions

Related Forums