Link to home
Start Free TrialLog in
Avatar of snooflehammer
snooflehammerFlag for Australia

asked on

VB Script to alert when message sent without attachment in Outlook

I want to create a rule in Outlook that checks an outgoing message for the words any word beginning with "attach" and checking if there is in fact an attachment.

If no attachment is found I want the message to be moved to Drafts and the user notified that they tried to send a message mentioning an attachment but there was no such attachment.

This can almost but not quite be achieved by the inbuilt rules. I believe I need to create a custom action, maybe.

I realise there are circumstances where the word attach will be used and there is no intention to send an attachment :)
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Place the code into thisoutlooksession

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

    If InStr(Item.Body, "attach") > 0 Then
        If Item.Attachments.Count < 1 Then
            If MsgBox("The message body mentions an attachment, but none found." & Chr(13) & Chr(10) & "Send anyway?", vbYesNo + vbDefaultButton2 + vbExclamation, "Attachment Missing") = vbNo Then
                Cancel = True
            End If
        End If
    End If

End Sub

Open in new window


What this does is to cancel the send leaving it in the outbox ... any good?

Chris
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of snooflehammer

ASKER

Thanks, Chris. Perfect.
Neat, elegant, does the job :)