A few weeks ago I set up my first droplet on Digital Ocean. It’s the first time I’ve been solely responsible for maintaining a server and it’s been quite the learning curve. The most frustrating thing has been trying to send emails from the server.
This list of recipes is mostly for my own future reference, but hopefully it will be useful for someone else as well. My droplet is running Ubuntu 16.04.
Finding out why your emails aren’t sending
service sendmail status reported that sendmail was exiting soon after I started it, but not why.
I found a couple of log files in /var/log
, which helped me get through the first hurdles, but were mysteriously silent about the last error that I encountered.
journalctl -u sendmail.service
did spit out the relevant error message but it was part of a massive several-screens-wide string and easily lost among other messages.
Eventually the most convenient option I found was to run sendmail -bp
, which is supposed to show you a list of items in the queue but spat out the ‘group writable directory’ error message that I’d been getting, without any of the fluff.
Fixing ‘Cannot open {filepath}: Group writable directory’ errors
This message drove me nuts. There’s only so many times you can check that a directory is not group writable before you throw your computer out the window. Googling it gave me a lot of hits but the first few (even my trusty StackOverflow) didn’t help me to actually fix it.
This message pops up because every parent directory of the path in question needs to be not group writable. In my case it was actually the root / directory that was affected, and running chmod 755 /
fixed it for me.
Emptying the queue
Let’s say you’ve been struggling with the message above for a while and don’t want your system to fire off every email it’s generated during that time when you finally get it right. Here’s how to properly empty the queue so that those emails are gone forever (h/t to StackOverflow user weeheavy for this one):
- Stop sendmail
rm /var/spool/mqueue/*
(remove from current queue)rm /var/spool/mqueue-client/*
(remove completely so they won’t be requeued)mailq
(confirm that the queues are empty)- Start sendmail
I finally managed to receive my first email message from my droplet last night – onto the next challenge!