Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim strSubject As String
Dim StrTo As String
Dim strBody As String
Dim mypeople As Variant, i As Integer, m As Integer
Dim myAttachments As Variant, at As String, atC As Integer
On Error GoTo e
strSubject = Item.Subject
StrTo = Item.To
strBody = Mid(Item.Body, InStr(Item.Body, " ") + 1, InStr(Item.Body, ",") - InStr(Item.Body, " ") - 1)
On Error GoTo 0
mypeople = Array(".kumar@******", "abc@xyz.com", "abc1@xyz.com", "abc2@xyz.com", "abc3@xyz.com", "abc4@xyz.com", "abc5@xyz.com", "abc6@xyz.com", "abc7@xyz.com", "abc8@xyz.com", "abc9@xyz.com", "abc10@xyz.com", "abc11@xyz.com", "abc12@xyz.com", "abc13@xyz.com", "abc14@xyz.com", "abc15@xyz.com", "abc16@xyz.com", "abc17@xyz.com", "abc18@xyz.com", "abc19@xyz.com", "abc20@xyz.com")
Dim mail As Outlook.MailItem
Set mail = Item
Dim recips As Outlook.Recipients
Dim recip As Outlook.Recipient
Dim pa As Outlook.PropertyAccessor
Dim StrEmail As String
Const PR_SMTP_ADDRESS As String = _
"http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
Set recips = mail.Recipients
For Each recip In recips
Set pa = recip.PropertyAccessor
StrEmail = StrEmail & "," & pa.GetProperty(PR_SMTP_ADDRESS)
Next
StrEmail = Mid(StrEmail, 2)
For i = LBound(mypeople) To UBound(mypeople)
If InStr(LCase(StrEmail), mypeople(i)) Then m = m + 1
Next i
If Not m - 1 <> (Len(StrEmail) - Len(Replace(StrEmail, ",", ""))) Then Exit Sub
Prompt$ = "Verify it " & vbNewLine & "Subject - " & strSubject & vbNewLine & _
"Mail to - " & StrEmail & vbNewLine & _
"Person - " & strBody & vbNewLine & vbNewLine & "Are you sure you want to send the Mail?"
If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Email Confirmation") = vbNo Then Cancel = True
'=============================================================
Set myAttachments = mail.Attachments
atC = myAttachments.Count
If atC > 0 Then
For i = 1 To atC
at = at & "," & myAttachments.Item(i).DisplayName
Next
MsgBox Mid(at, 2)
End If
'=============================================================
Exit Sub
e:
Cancel = True
MsgBox "Pls Recheck as per pattern : To[@], Subject[<>], Body[ ,]"
End Sub