Consulting

Results 1 to 7 of 7

Thread: Solved: Searching Body and Attachments

  1. #1
    VBAX Regular
    Joined
    Nov 2005
    Posts
    39
    Location

    Solved: Searching Body and Attachments

    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!

  2. #2
    VBAX Regular
    Joined
    Nov 2005
    Posts
    39
    Location
    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.

    [vba]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[/vba]

  3. #3
    VBAX Regular
    Joined
    Nov 2008
    Posts
    7
    Location

    What I

    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.


    Quote Originally Posted by GMan
    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.

    [vba]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[/vba]

  4. #4
    VBAX Regular
    Joined
    Nov 2005
    Posts
    39
    Location
    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!

  5. #5
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    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

    Quote Originally Posted by GMan
    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.

    [vba]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[/vba]

  6. #6
    VBAX Regular
    Joined
    Nov 2005
    Posts
    39
    Location
    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?

  7. #7
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    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).

    Quote Originally Posted by GMan
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •