You are on page 1of 4

Function UNameWindows() As String

UNameWindows = Environ("USERNAME")
End Function

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)


Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim

oMail As Outlook.MailItem
sSubject As String
StrName As Variant
a As String
z As Variant
m As Variant
Clientlist(0 To 8) As String
foundclient As String

foundclient = False

Clientlist(0) = "gettyimages.com"
On Error GoTo Lastline
Set oMail = Application.ActiveInspector.CurrentItem
Set Mail_Object = CreateObject("Outlook.Application")

Dim recips As Outlook.Recipients


Dim recip As Outlook.Recipient
Dim pa As Outlook.PropertyAccessor
Dim emailcount As Integer
emailcount = 0

Const PR_SMTP_ADDRESS As String = _


"http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
Set recips = oMail.Recipients
For Each recip In recips
Set pa = recip.PropertyAccessor
z = pa.GetProperty(PR_SMTP_ADDRESS)

emailcount = emailcount + 1
m = m & " " & z

Next
For i = LBound(Clientlist) To UBound(Clientlist)
If InStr(1, m, Clientlist(i)) > 1 Then
foundclient = True
Prompt$ = "Mail is being sent to the Client. Do you still want to send the mail?
"
If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground,
"Do you still want to send the mail?") = vbNo Then
Cancel = True
End If

End If
Next

If foundclient = False And InStr(1, m, "eclerx.com") = 0 Then


Prompt$ = "Mail is being sent outside eclerx domain. Do you still want to send t
he mail?"
If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground,
"Do you still want to send the mail?") = vbNo Then
Cancel = True
Else
Email_Subject = "Mail sent outside eClerx" & Subject
Email_Send_From = ""
'Email_Send_To = "ameya.parsekar@eclerx.com" '& ";
Email_Cc = ""
Email_Bcc = ""
Email_Body = UNameWindows & " has sent an email outside eClerx to following reci
pients " & m
On Error GoTo debugs
Set Mail_Object = CreateObject("Outlook.Application")
Set Mail_Single = Mail_Object.CreateItem(0)
With Mail_Single
.Subject = Email_Subject
.To = Email_Send_To
.CC = Email_Cc
.BCC = Email_Bcc
.Body = Email_Body
.Send
End With
debugs:
End If

'a = oMail.Recipients

'
End If

sSubject = oMail.Subject
Dim strSubject As String
Dim lngres As Long
strSubject = Item.Subject
strSubject1 = oMail.Recipients.names

'

oMail.BodyFormat = olFormatHTML
'MsgBox InStr(1, UCase(Item.Body), ".JPG")
If Trim(strSubject) = "" Then
Prompt$ = "Subject line is blank. Are you sure you want to send the
Mail?"
If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground,
"Check for Subject line") = vbNo Then
Cancel = True
End If
End If
If InStr(1, UCase(Item.Body), ".PNG") <> 0 Or InStr(1, UCase(Item.Body),
".JPG") <> 0 Or InStr(1, UCase(Item.Body), ".BMP") <> 0 Then
If Item.Attachments.Count = 1 Then
lngres = MsgBox("'Attach' in body, but no attachment - send anyway?"
, _
vbYesNo + vbDefaultButton2 + vbQuestion, "You asked me to warn you..
.")
If lngres = vbNo Then Cancel = True
End If
End If
If Item.Attachments.Count = 0 And InStr(1, UCase(Item.Body), "ATTACH") <
> 0 Then
lngres = MsgBox("'Attach' in body, but no attachment - send anyway?"
, _
vbYesNo + vbDefaultButton2 + vbQuestion, "You asked me to warn you..
.")
If lngres = vbNo Then
Cancel = True
End If
End If
If Item.Attachments.Count = 0 And InStr(1, UCase(Item.Body), "PFA") <> 0 Then
lngres = MsgBox("'Attach' in body, but no attachment - send anyway?"

, _
vbYesNo + vbDefaultButton2 + vbQuestion, "You asked me to warn you..
.")
If lngres = vbNo Then
Cancel = True
End If
End If

Lastline:
End Sub

You might also like