Checking outgoing messages for attachments

Posted on 2006-05-05
Last Modified: 2010-04-08
Hello. I would like to check when people press the 'Send' button (on a new message) that

If any of the words 'enclosed, attached or attachment' are in the body of the email then it checks to see whether an attachment is present, and if not it alerts the user of this fact and gives them a chance to attach a file (or ignore the warning)
Question by:butterhook
    1 Comment
    LVL 76

    Accepted Solution

    Greetings, butterhook.

    This one is pretty simple.  Here's the code.  This must go in the ThisOutlookSession module.

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
        Dim arrWords As Variant, _
            strWord As Variant, _
            intResponse As Integer
        If Item.Class = olMail Then
            If Item.Sent = False Then
                arrWords = Array("enclosed", "attached", "attachment")
                For Each strWord In arrWords
                    If InStr(1, LCase(Item.Body), strWord) > 0 Then
                        If Item.Attachments.Count = 0 Then
                            intResponse = MsgBox("Did you forget to attach something?", vbYesNo + vbExclamation, "Attachment Check")
                            If intResponse = vbYes Then
                                Cancel = True
                            End If
                        End If
                        Exit For
                    End If
            End If
        End If
    End Sub


    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Learn more about the importance of email disclaimers with our top 10 email disclaimer DOs and DON’Ts.
    Create high volume marketing opportunities using email signatures with these top 10 DOs and DON'Ts of email signature marketing.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now