I’ve been on a bit of a roll with the bavaserver setup, and I am going to try and ride that energy for a bit longer before the semester gets into full gear at Reclaim Hosting and any remnants of free time quickly disappear. After getting a firewall setup, another outstanding task was managing email on the server. I did have Postfix installed, which is an open source mail transfer agent (MTA), and I set this up to forward internal, server-based messages. This was dead simple, I basically followed this guide on “How to redirect local root mail to an external email address on Linux.”
I did a quick:
sudo nano /etc/aliases
And once that file was open I added my desired forwarding gmail address:
root: [email protected]
After that, I ran the following command:
And restarted Postfix:
service postfix restart
Finally, I tan the this command to send a test email
echo "Subject: sendmail test" | sendmail -v
That worked, and now I was getting all the internal server email to my gmail address so I know what’s going on, but be careful of what you wish for. The emails come fast and furious, and can quickly overwhelm your inbox. In particular, the CSF firewall was particularly loud with emails, so I needed to manage some of that. The CSF configuration file is the place to start:
sudo nano /etc/csf/csf.conf
In that file there are several alerts set to “1” (or turned on) that can be turned off by changing that value to “0”. Such as the LF_PERMBLOCK_ALERT:
This brought the email volume down considerably, but I was still getting emails about too excessive resource usage for various processes, so this guide was useful for adding certain commands to a CSF ignore file:
Use the following code on Centos 7 to edit the csf.pignore file:
sudo nano /etc/csf/csf.pignore
After that, add the following for the command line you get in the offending emails. In this example I am ignore the emails from the do-agent:
After that, you should get far fewer system emails forwarded on to your email.
The other thing I did was run the emails sent by my WordPress through Mailgun, a third-party, API-driven service for sending email. My blog will send very few emails, so I run little risk of hitting the 10,000 email limit, but I’ll be notified about those trackbacks, spam, and unapproved comments all the while 🙂 In Mailgun you have to verify the domain you want to send emails from, I used , and the address is [email protected] To verify the domain you need to add TXT records and CNAMES to your DNS zone editor, and then you can get the API or SMTP details you need to send emails. I’ll spare you the details here given there are much better guides that take you through it, but transaction emails services have been a thing for a while now given most nextgen apps want to (or have to) abstract application based email from the server stack, which makes good sense. I wouldn’t call WordPress a nextgen app by any means (I prefer old gold), but I like the idea of reminding myself of how the transactional email services work, not to mention they are quite reliable. The last piece was installing the WP Mail SMTP plugin, and adding my secret API key from mailgun and I was up and running in seconds.
# Swaks is an smtp of CURL, install it first: curl http://www.jetmore.org/john/code/swaks/files/swaks-20130209.0/swaks -o swaks # Set the permissions for the script so you can run it chmod +x swaks # It's based on perl, so install perl sudo apt-get -y install perl # now send! ./swaks --auth \ --server smtp.mailgun.org \ --au [email protected]_DOMAIN_NAME \ --ap 3kh9umujora5 \ --to [email protected] \ --h-Subject: "Hello" \ --body 'Testing some Mailgun awesomness!'
One fun bit was being able to send emails to myself via command line after installing the swiss army knife for SMTP (swaks). I found the above code here, and I sent more than few command line emails like I was using Pegasus again.
And, that about does it for email on the new server right now, feels good to get as much of this down as possible because the bava as outboard brain will be very useful when my server crashes and I have no idea what to do 🙂
Image credit: Awesome Email GIF in header