All of us have done it: sending a mail without a subject or sending a mail where we wanted to attach something and forgot to attach it.

The following code-snipped can be added to the Visual Basic Editor (Alt-F11) to show a warning if the subject is empty or in the body is the text “attach” or “anhang”.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    If Item.Subject = "" Then
        Cancel = MsgBox("There's no subject, send anyway?", vbYesNo + vbExclamation, "No Subject") = vbNo
    End If
 
    If InStr(1, Item.Body, "attach", vbTextCompare) > 0 Or InStr(1, Item.Body, "anhang", vbTextCompare) > 0 Then
        If Item.Attachments.Count = 0 Then
            answer = MsgBox("There's no attachment, send anyway?", vbYesNo)
            If answer = vbNo Then Cancel = True
        End If
    End If
End Sub

Leave a Reply

Your email address will not be published.

*