Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

An AppleScript to trash empty emails Apps
I hate how emails with no subject, no sender, and no content appear in my InBox in Mail. So I wrote an AppleScript to use as a Mail rule to automatically move these void emails to the trash. Open up Script Editor, and paste in this code.

Save the file to your user's Library -> Scripts -> Applications -> Mail folder, and call it Void Email Trasher.scpt. Then open up Mail, go to Preferences, and click the Rules icon. Create a new rule (give it a description such as "Void Email Trasher"), and set these conditions:

If "any" of the following conditions are met:
  • Select "Every Message" from the drop-down menu in the first section.
  • Perform the following actions: "Run AppleScript" from the drop-down menu, then click Choose and find Void Email Trasher.scpt where you saved it earlier.
Then hit OK to save your rule. Now any new blank messages will be automatically trashed.

[robg adds: You could also use a straight Mail rule to do most of this. Check for 'all' conditions met, and set 'Subject,' 'is equal to,' and then a blank box. Add a similar condition for 'From' and 'Content.' The only thing you won't be able to do this way is check for the blank line (and do the 'or' logic for the blank or empty line).

My apologies for the above -- I tested it, right up to the 'save the rule' step.

I haven't tested the AppleScript, as I have yet to receive an email that would be caught by it.]
  • Currently 2.80 / 5
  You rated: 3 / 5 (5 votes cast)

An AppleScript to trash empty emails | 14 comments | Create New Account
Click here to return to the 'An AppleScript to trash empty emails' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to trash empty emails
Authored by: bbumgarner on Feb 27, '06 07:46:25AM


I tried setting up a set of rules as you suggested and recieved this error message:


At least one of the conditions has an empty expression field. Please fill in the field or remove the condition.

I am using Mail 2.0.5 on System 10.4.5. I haven't tried the Applescript code yet, but I'm going to take a look at it as I, too, hate getting these messages.

Brad Bumgarner, CTA

[ Reply to This | # ]
Just curious…
Authored by: jiclark on Feb 27, '06 08:25:57AM

…but why would anyone be getting such emails. I don't believe I've ever seen anything like that, and it sounds like Rob hasn't either. I do have Mail setup to view plain text by default, so some html email shows up blank, but only in the main body. A quick command-[ will show me the message (without images, of course).

I wonder what would create messages that come in as described in this hint?

[ Reply to This | # ]
Just curious…
Authored by: GaelicWizard on Feb 27, '06 08:42:13AM

iGet spam that is just empty. It seems like its aborted or not-finished spam messages. The from field is bogus, but subject and content are blank.



[ Reply to This | # ]
Just curious…
Authored by: TigerKR on Feb 27, '06 11:22:33AM

Apparently, blank emails can sometimes cause junk filters to flip-out and not process anything after the blank email. At least, this used to be the case, and hopefully the programmers of today are wise to this tactic.

But regardless of whether or not they cause the junk filter to pop a fuse, these empty void messages end up in my InBox and serve to annoy me royally.

For the record, I get them all of the time, and an additional annoyance is that Mail can't delete them from the server by itself, so sometimes they fill up my trash mailbox (using the applescript), adding a new entry every time Mail checks the server. The only way to delete these messages from the server is to use the Mail command-i key combination to delete the message straight from the server.

The command-i tip can be found here:

[ Reply to This | # ]
An AppleScript to trash empty emails
Authored by: TigerKR on Feb 27, '06 10:56:16AM

Rob, Mail won't allow empty fields when defining a rule. But if you could use an empty field, because the 'content' can be either 'null' or 'new-line', and there is no way to use a combination of 'any' and 'all' for Mail's rules, there is no way to set-up the rules in Mail without the applescript, unless you used two different rules.

Rule 1. IF ALL -> Subject = "" Sender ="" Content = "" THEN DELETE
Rule 2. IF ALL -> Subject = "" Sender ="" Content = 'new-line' THEN DELETE

But that's a moot point if you can't use blank fields in Mail's rules.

[ Reply to This | # ]
An AppleScript to trash empty emails
Authored by: toor on Feb 27, '06 11:24:15AM

Since Mail won't accept an empty field, here my humble way to catch empty msgs.:

If any

From Does not contain . ( that's a period, at least one must be in any valid msg. "from" address )

To Does not contain @ ( that's a shift-2, one must be in any valid msg. "to" address )


Move msg. to Trash
Set Color of text to Red ( to show for review in case of false postitves )
Stop evaluating rules.

HTH, salt to taste, YMMV.

[ Reply to This | # ]
An AppleScript to trash empty emails
Authored by: fracai on Feb 27, '06 11:56:35AM

won't this match e-mails that are BCC'd to you resulting in an empty To field?

i am jack's amusing sig file

[ Reply to This | # ]
An AppleScript to trash empty emails
Authored by: toor on Feb 27, '06 01:04:17PM

Could be, unless one considers those spam too. ;-)

Changing "If any" to "If all" should fix that, and/or substitute the "To:" filed w/ the "Subject:" field, etc.

[ Reply to This | # ]
An AppleScript to trash empty emails
Authored by: mfichtner on Feb 27, '06 12:00:48PM
I get quite a number of these completely empty messages each week. My AppleScript to catch them, however, looks a bit different: Instead of checking message contents (which can be quite slow for large messages) my script looks at the number of recipients. If sender and subject are empty plus there are zero recipients, the message is trashed.

[ Reply to This | # ]
An AppleScript to trash empty emails
Authored by: mark hunte on Feb 27, '06 01:33:22PM

You CAN do the Mail rules, just add a 'Date sent' is 'less than' to the end of the ones rob suggests.

I get no error when I did this but as I do not get these mails I can not say if it will catch them.


[ Reply to This | # ]
An AppleScript to trash empty emails
Authored by: Peganthyrus on Feb 27, '06 02:28:19PM

I get these, and it didn't work. These blank mails are highly malformed; there <i>is</i> no To: From: or Subject: line, or in fact anything after the list of Received: lines and my mail provider's spam checking.

I was able to add a new header to check on, X-Spam-Status, and get these by doing a rule for all of "X-Spam-Status contains MISSING_DATE" and "X-Spam-Status contains MISSING_SUBJECT". Do apple-alt-u on one of these messages to see the raw text if you get them; if you're lucky, your mail provider runs antispam stuff that leaves notes, too.

[ Reply to This | # ]
An AppleScript to trash empty emails
Authored by: cougar718 on Feb 27, '06 08:26:16PM

I have never received an email that has a blank from, subject, and body... However I have received email with no subject and most of the time it was junk. So when that type of email is received, I just remove them using a rule that runs an AppleScript.

Rick alias cougar

[ Reply to This | # ]
From a hint submission
Authored by: robg on Mar 17, '06 05:40:43AM
Anonymous wrote:
robg indicated that a Mail rule wouldn't work - actually, it does. You just have to think perpendicularly. Instead of checking to see if Subject/From/To are blank (which you cannot), check if From/To do *not* contain @. Easy-peesy. Works for me, I was getting 30+ blanks a day.

[ Reply to This | # ]
This hint still applies in 2013!
Authored by: The Eck on Jul 18, '13 02:24:48PM

Adding a comment several years after this thread petered out.

I'm on OS X 10.8.3, Mail 6.5, have an IMAP account that suddenly had several incomings with no sender, no recipient, no subject, no body. I quickly discovered that you simply can trash them, as others above have noted. I also quickly began a search for a resolution and came upon this thread. I created a rule based on Rob's suggestion above and I'm pleased to report that looking for "does not contain" "@" for sender/receiver fields indeed deleted the emails.

thanks Rob, if you're still checking in from time to time, and to all the others who fine-tuned this tip. Your community help is really appreciated.

[ Reply to This | # ]