mail

How to get your server's emails through Gmail's spam filter with Exim

There's one thing that most first-time server administrators have in common: they have to either learn a lot about how email and spam filters work, or they offload email delivery entirely to a third party.

The latter option is often the best option, since successful email delivery is a crazy complicated endeavor. I know, because I've worked on two separate medium-volume email delivery systems in the past (over 1,000,000 emails/month, to hundreds of thousands of recipients), and for both of them, I spent likely 1,000+ hours on email delivery problems.

But for many smaller sites, non-profits, and side projects, there's no budget for a reliable 3rd party email delivery service.

Recently, I was rebuilding a personal photo sharing website (just used for myself and my family and friends), and I decided to wipe the server clean and start over with an Ansible-based configuration that I could deploy locally and to any cloud environment. For email delivery, I decided to install Exim on top of a CentOS 7 minimal base image, and I used Drupal/PHP's mail functionality to pass messages to Exim.

I hit inbox zero!

It's been over three years since the last time I completely drained my main inbox, and reached #inboxzero.

I've been hitting my inbox hard for the past year now, constantly fighting to get it down to < 50 emails... but every time I hit a holiday weekend, worked on a larger home project, or did something like publish a new project, the inbox would start flooding a bit more. I finally made it my goal this year to purge the emails and hit zero messages by the end of the July 4th weekend—and it worked!

Inbox Zero - July 4 2016

Here are a few things I've been doing this year to try to keep the volume down even further (ironically, the closer I've gotten to zero, the more daily emails I get—now up to about 120/day non-spam):

Viewing email in Linux using postfix's mailq and postcat

When I'm developing using the Drupal Development VM, or checking into email processing on any of my servers, I usually use postfix to handle mail sending. Postfix is simple, preinstalled on most Linux distributions (and easy to set up if not), and is easy enough to use.

Here are the most common commands I use when either developing or troubleshooting email in production:

  • mailq - print a list of all queued mail
  • postcat -vq [message-id] - print a particular message, by ID (you can see the ID along in mailq's output)
  • postqueue -f - process the queued mail immediately
  • postsuper -d ALL - delete ALL queued mail (use with caution—but handy if you have a mail send going awry!)

There are many other helpful commands and scripts to help deal with mail (e.g. deleting all messages to a certain domain, or deleting specific message IDs easily), but these are the main ones I use during day-to-day development and troubleshooting.

Route local emails to another email address using Postfix on Linux

When I set up new servers, I like to make sure any system messages like cron failures, server issues, or emails that are routed to [email protected] (where 'example.com' is the hostname of the server—meaning emails to that domain will get routed through the server itself and not hit an external MX server unless postfix/sendmail is configured correctly) are sent to my own email address.

It's relatively straightforward to route emails to internal users (like webmaster, root, etc.) to an external email address; you simply need to edit the /etc/aliases file, adding a rule like the one below, then run the command sudo newaliases:

webmaster: root

# Person who should get root's mail
root: [email protected]

By default, most internal users are routed to root as well (including webmaster), so setting an external email address (or a list of addresses, separated by comma) for the root account will allow you to more easily see what's happening on your server. Don't forget to run sudo newaliases to pick up the changes!

Mac OS X Mail - Exchange Account Stuck unless Mail Quit and Restarted?

I was having this particular problem off and on when using Mac OS X Mail on my work Mac, which was set up to use our corporate exchange server, and an 'Exchange 2007' Mail account: Every so often, Mail would quit getting new messages in the inbox, and when I checked the 'Activity' window, I would get the following error:

(Screenshot to be posted here)
("Opening Mailbox — Requesting Latest Information")

Sometimes, simply hitting the 'stop sign' would allow me to get new messages, but the problem would always crop up again. Other times, I'd pull out my Mac laptop, which was set up to use IMAP instead of Exchange (long story, details don't matter), and after syncing it up with the server, and restarting Mail on my main Mac, the problem would go away.

Only today, after finding this forum thread on Apple's Discussion Forums, did I find the source of the problem:

Mac OS X Mail App: Deleted Messages Showing in Inbox

Earlier today, when I was working on fixing a few little inconsistencies in my mail inboxes (I currently sync 5 different accounts (with a plethora of email addresses feeding into the various accounts)), deleted messages started showing in some of my inboxes in Mac OS X's built in Mail app. They were greyed out, but not enough so that I could easily distinguish non-deleted messages...

After looking around online for a while, and not finding any fixes for this problem (I get so many emails that showing deleted messages basically makes my inbox unusable), I thought to search the Mail help for an answer.

Show Deleted Messages
Pesky little menu options!

I found a little menu item labeled "Show Deleted Messages" (Command-L keyboard shortcut), which somehow had been selected at some point (I can't think of why I would hit command-l in Mail... but I guess I did). Unchecking that hid the messages. Problem solved!

New MobileMe Mail Features - Server-Side Rules!!

The day has finally come for cloud-based rules in the MobileMe world :-)

I have been an iTools -> .Mac -> MobileMe user through the whole ride (starting the day after iTools was open for new users), and the service has had me wanting to leave for some time... and I still might in a year or two. However, server-side mail sorting rules (along with other new features of the online webmail client) are a huge boon for me:

Rules to keep your email organized everywhere. Mail rules help you reduce inbox clutter by automatically filing messages into folders you select ahead of time. Set them up at me.com, and your rules organize your incoming email on the web and everywhere else — on your iPhone, iPad, iPod touch, Mac, and PC.

One of the most annoying things about using my iPad as a laptop replacement is the fact that rules aren't applied to my emails. I get about 100-150 emails a day, and about 50 of them are sorted by rules (into archival folders, routed to the trash, etc.), and I don't want them marked as Junk.

Taming Mac OS X Mail - Previous Recipients

Mac OS X's Mail program has a very handy feature called 'Previous Recipients' that does a very nice thing: It saves a list of every person and email address you've ever sent an email to. Then, it automatically fills in that person's email address when you type it or the person's name in the 'To' field in a new message. This is usually a good thing, because it saves you time (you don't have to look up the address again!).

However, there are times when you want to send an email to a specific email address for that person, and the email address that Mail automatically inserts is—gasp!—the wrong address. For example, I want to send an email to my friend John, so I type in "John" in the To field. Mail fills in the address I usually send emails to: [email protected]. But I want to send the mail to John's alternate address, [email protected]... and I want to start sending emails to that address rather than to his first email address all the time. There are two easy solutions to this problem: