Hack #62. Warn Before Sending Gmail Messages with Missing Attachments
Never again forget to attach a file to your email.
It's too easy to forget to attach files when sending email. You send off the message, and a few minutes later you get a puzzled reply asking, "Was there supposed to be a file with this?"
Some desktop mail applications use heuristics to check for this condition and prompt you before sending your message. However, I have never seen this incorporated in a web mail application. Using Greasemonkey, we can guess with pretty good accuracy that a message was supposed to contain an attachment if it contains words such as attachment or files. If such a message actually contains no files, then we can show a warning before sending the message.
The Code
This user script runs in both the Reply and Compose frames in Gmail. These can be identified by their view=cw and view=page query string parameters.
The script listens for click events on the Send buttons. When the user clicks one of them, the script gets the contents of the message text box and scans each line of the message for any occurrences of specific keywords. Since messages can contain quoted text copied from a previous message, we intentionally ignore lines that start with >.
If we find any occurrences of attachment or files, we check whether there are any attachments. If there are no attachments, we prompt the user to confirm that she really wants to send the message.
Tip
You can access forms, form elements, images, and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access