Thursday, August 14, 2014

Set up your server to forward root emails to an external email

So I mentioned in my previous post that I've setup our servers to forward emails for root to an external email. As long as your ISP isn't blocking you from sending from your own SMTP, this should work. So if there isn't anything blocking you from sending how do you forward root emails to an external email?

With a default CentOS 6.2 install, you can usually send emails already. So let's test to see if you can receive emails from your server. Run the following command:

echo "Testing message" | mail -s "Testing from server" youremail@domain.com
 
replacing "youremail@domain.com" with your own email of course. If you don't get the email, then your ISP may be blocking you from sending. If you do receive it, then we can continue.
First, you edit /etc/aliases. On our CentOS 6.2 systems, it's the last line that's important. By default it's:

# Person who should get root's mail
#root:      marc
 
It's commented out, and set to forward to "marc". So, uncomment it by removing the "#" character in front of root. Then change "marc" to an email address you want to receive notifications. So now, it should look something like this:

# Person who should get root's mail
root:       notifications@example.com
 
Save the file. Now, in order for sendmail (or in CentOS 6.2's case, postfix) to see the new alias, you have to run the following in your terminal:

newaliases
 
If there's no output, then it should have worked.
So now we can test sending to just "root":

echo "Testing message" | mail -s "Testing from server" root
 
Now, whoever is set to receive root's emails will get that message.
You can also check your mail queue to see if any messages are "stuck". The command is:

mailq
 
If your test messages are stuck there, then that's probably something you should talk to your ISP about.

No comments:

Post a Comment