A
Arun
The story begins like this: Many a times I forget the attachments in the mail
across. So I wanted to write a small trigger on the outlook client which
checks if the sent message contained words like 'attach' and check if there
is any attachment in the mail or not, before sending the mail. If the
attachment is missing exception is raised to the user. The code for it is as
below:
---------------------------------------------------------------------
Public Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim prompt As String
Dim checkBodyAttachStr, checkSubAttachStr As Integer
Dim checkAttachmentCnt As Integer
Dim ForbiddenString(10) As String
Dim I, MaxWords As Integer
Dim AttachWordPresent As Boolean
MaxWords = 3
ForbiddenString(1) = "Attach"
ForbiddenString(2) = "PFA"
ForbiddenString(3) = "attched"
For I = 1 To MaxWords
checkBodyAttachStr = InStrRev(Item.Body, ForbiddenString(I), ,
vbTextCompare)
checkSubAttachStr = InStrRev(Item.Subject, ForbiddenString(I), ,
vbTextCompare)
If ((checkBodyAttachStr <> 0 Or checkBodyAttach <> Null) Or
(checkSubAttachStr <> 0 Or checkSubAttach <> Null)) Then
AttachWordPresent = True
Exit For
End If
Next I
checkAttachmentCnt = Item.Attachments.Count
If ((AttachWordPresent = True) And (checkAttachmentCnt <= 0)) Then
prompt = "Oh Dear, You forgot the Attachment! Continue Sending?"
If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo Then
Cancel = True
Else
Cancel = False
End If
End If
End Sub
---------------------------------------------------------------------
When the mail account is configured as 'Pop3' or 'IMAP' this code in
'ThisOutlookSession' fires and I get proper response (it works the way it
should). But when the mail account is configured as 'Microsoft Exchange
Server account (MAPI)' and if the mails are seen on the exchange server, this
code does not work.
Questions:
1. Is there any other (better) way of doing a similar check of attachments
in sent mails?
2. What is the difference in VBA event when the mail account is configured
as 'POP3/IMAP' and 'MS Exchange Server account'?
Looking forward to hearing from you
Regards
Arun
across. So I wanted to write a small trigger on the outlook client which
checks if the sent message contained words like 'attach' and check if there
is any attachment in the mail or not, before sending the mail. If the
attachment is missing exception is raised to the user. The code for it is as
below:
---------------------------------------------------------------------
Public Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim prompt As String
Dim checkBodyAttachStr, checkSubAttachStr As Integer
Dim checkAttachmentCnt As Integer
Dim ForbiddenString(10) As String
Dim I, MaxWords As Integer
Dim AttachWordPresent As Boolean
MaxWords = 3
ForbiddenString(1) = "Attach"
ForbiddenString(2) = "PFA"
ForbiddenString(3) = "attched"
For I = 1 To MaxWords
checkBodyAttachStr = InStrRev(Item.Body, ForbiddenString(I), ,
vbTextCompare)
checkSubAttachStr = InStrRev(Item.Subject, ForbiddenString(I), ,
vbTextCompare)
If ((checkBodyAttachStr <> 0 Or checkBodyAttach <> Null) Or
(checkSubAttachStr <> 0 Or checkSubAttach <> Null)) Then
AttachWordPresent = True
Exit For
End If
Next I
checkAttachmentCnt = Item.Attachments.Count
If ((AttachWordPresent = True) And (checkAttachmentCnt <= 0)) Then
prompt = "Oh Dear, You forgot the Attachment! Continue Sending?"
If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo Then
Cancel = True
Else
Cancel = False
End If
End If
End Sub
---------------------------------------------------------------------
When the mail account is configured as 'Pop3' or 'IMAP' this code in
'ThisOutlookSession' fires and I get proper response (it works the way it
should). But when the mail account is configured as 'Microsoft Exchange
Server account (MAPI)' and if the mails are seen on the exchange server, this
code does not work.
Questions:
1. Is there any other (better) way of doing a similar check of attachments
in sent mails?
2. What is the difference in VBA event when the mail account is configured
as 'POP3/IMAP' and 'MS Exchange Server account'?
Looking forward to hearing from you
Regards
Arun