Managing Mail on the bavaserver

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.”

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: yourexternalemailaddress@gmail.com

After that, I ran the following command:

newaliases

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:

LF_EMAIL_ALERT =0

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:

https://www.interserver.net/tips/kb/disable-lfd-excessive-resource-usage-alert/

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:

exe:/opt/digitalocean/bin/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 postmaster@. 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 postmaster@YOUR_DOMAIN_NAME \
        --ap 3kh9umujora5 \
        --to bar@example.com \
        --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

This entry was posted in bavatuesdays, sysadmin and tagged , , . Bookmark the permalink.

3 Responses to Managing Mail on the bavaserver

  1. Loving your narration of this whole process, Jim! Very fascinating.

    • Reverend says:

      Thanks Lauren,

      Trying to get as much down as possible so I don’t forget, and also trying to limit my lifelines to Tim as much as possible. I find for me learning in spurts like this when it is a real, yet not mission critical, project is ideal for me. This blog has always been the site of my learning and experimenting, so it feels good to get back to that.

      Long live the bava!

  2. Pingback: Reclaim Arcade: the Email Game | bavatuesdays

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.