PDA

View Full Version : Solved: Searching Body and Attachments



GMan
08-15-2008, 11:55 AM
In an effort to take care of peoplse sensitive information, my company has required some e-mail to be encryted. However, we have years of developing the habit to quickly click send. I am working to develop a macro that will search the file attachments and Body of th e-mail for a string of text. If the text is found then the user is prompted to determine if the mail for be encrypted.

I have got the macro attached to the SEND Button and the prompts are working. But can anyone help me with the searching of the Attachements and/or Body of the mail.

Thanks!

GMan
09-08-2008, 12:30 PM
Well, here is proof that if you hunt around long enough you will find something that gets you close to what you are looking for. To solve my above questions I came up with the following macro. The only compromise I had to make is to not search inside attached files. So instead, I prompt the user to see if the mail should be encrpted if there is an attachment.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Const cSSN = "SSN"
Dim strMsg As String
Dim stBody As String
Dim res As Long
Dim flSSN As Boolean

stBody = Item.Body
If Item.Attachments.Count <> 0 Or _
InStr(1, stBody, cSSN) > 1 Then
strMsg = "Should this E-mail be Encrypted?" 'set Message
res = MsgBox(strMsg, vbYesNo, "Encryption") 'Display Message
If res = 6 Then 'Check if selected YES
MsgBox "Please follow your normal encryption process", vbInformation, "Encrypt E-mail"
Cancel = True 'Yes Clicked, do not send
End If
End If
End Sub

mavol
11-10-2008, 02:23 PM
I'm going to get the type of attachment, and if it is an excel or word document, I'm going to open an istance of that and search for the words....or at least I'm going to try.



Well, here is proof that if you hunt around long enough you will find something that gets you close to what you are looking for. To solve my above questions I came up with the following macro. The only compromise I had to make is to not search inside attached files. So instead, I prompt the user to see if the mail should be encrpted if there is an attachment.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Const cSSN = "SSN"
Dim strMsg As String
Dim stBody As String
Dim res As Long
Dim flSSN As Boolean

stBody = Item.Body
If Item.Attachments.Count <> 0 Or _
InStr(1, stBody, cSSN) > 1 Then
strMsg = "Should this E-mail be Encrypted?" 'set Message
res = MsgBox(strMsg, vbYesNo, "Encryption") 'Display Message
If res = 6 Then 'Check if selected YES
MsgBox "Please follow your normal encryption process", vbInformation, "Encrypt E-mail"
Cancel = True 'Yes Clicked, do not send
End If
End If
End Sub

GMan
11-11-2008, 06:32 AM
Thanks for the idea Mavol. I think that should cover 99% of what would be sent to our clients.

Looks like I have something new to play with! :yes

JP2112
11-12-2008, 08:21 AM
Your code assumes that the item being sent is an email. You should test for that by calling the TypeName function:

If TypeName(item) = "MailItem" Then
' your code here
End If


HTH,
JP


Well, here is proof that if you hunt around long enough you will find something that gets you close to what you are looking for. To solve my above questions I came up with the following macro. The only compromise I had to make is to not search inside attached files. So instead, I prompt the user to see if the mail should be encrpted if there is an attachment.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Const cSSN = "SSN"
Dim strMsg As String
Dim stBody As String
Dim res As Long
Dim flSSN As Boolean

stBody = Item.Body
If Item.Attachments.Count <> 0 Or _
InStr(1, stBody, cSSN) > 1 Then
strMsg = "Should this E-mail be Encrypted?" 'set Message
res = MsgBox(strMsg, vbYesNo, "Encryption") 'Display Message
If res = 6 Then 'Check if selected YES
MsgBox "Please follow your normal encryption process", vbInformation, "Encrypt E-mail"
Cancel = True 'Yes Clicked, do not send
End If
End If
End Sub

GMan
11-13-2008, 06:42 AM
Isn't it safe to make this assumption being that the code is in the Application_ItemSend section? What else could be sent that wouln't have a body and possibly an attachment within the body?

JP2112
11-13-2008, 10:45 AM
If you accept a task that someone assigns to you, you will send back a TaskRequestAcceptItem object. Also I believe the various meeting request responses you might send when accepting or declining a meeting would also qualify as not having attachments (or a body property you would need or want to check).


Isn't it safe to make this assumption being that the code is in the Application_ItemSend section? What else could be sent that wouln't have a body and possibly an attachment within the body?