Deleting old mail with archivemail

Archivemail is a tool for archiving or deleting old mail in mailboxes. It moves or deletes messages older than the specified number of days. Combined with cron, it’s the perfect tool for keeping constantly growing mail folders like spam or trash under control.

I use IMAP hosted with Pair Networks, but the discussion that follows should be broadly applicable to any remote or local mail server. For purposes of illustration, let’s assume we have the domain “”, our hosting account’s username is “account”, and the mailbox we will be working with is “”. Pair Networks uses mbox format, but to the best of my knowledge the following works equally well with maildir format.

To illustrate the use of archivemail, let’s give ourselves the task of automatically deleting messages in the Sent folder that are more than 30 days old.

Archivemail is available through the software repositories of most distributions and comes pre-installed on many web hosts.

First, test your syntax using the dry run and verbose options:

archivemail --dry-run --verbose --delete --days=30 /path/to/folder

The paths and names of your mail folders will vary from system to system. To provide two examples, on my remote mail server (using BSD, IMAP and mbox) the sent mail folder is:


and on my local box (using Linux, Evolution, IMAP, and mbox) it is:


Inspect the output of the dry run. If all is well, replace the options –dry-run and –verbose with –quiet and set it up as a daily cron job.

Consider applying the same technique to other mail folders that can benefit from cleaning, such as INBOX.Spam and INBOX.Trash. So long as the archivemail options being used are identical, you can combine multiple mail folders or boxes in a single command using the syntax archivemail [options] mailbox_1 mailbox_2…

Archivemail project site
Tidy up your mailboxes with Archivemail


About Warren Post

So far: Customer support guy, jungle guide, IT consultant, beach bum, entrepreneur, teacher, diplomat, over-enthusiastic cyclist. Tomorrow: who knows?
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

One Response to Deleting old mail with archivemail

  1. Pingback: Spam control on a mail server with SpamAssassin | Warren's tech notes

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s