Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I manage a micro linux server on Amazon EC2. Occasionally I get email sent to the root account and if I'm logged in, I'll get the notice:

You have new mail in /var/spool/mail/root

How do I get these emails sent to another email address (like user@gmail.com) instead?

share|improve this question

3 Answers 3

up vote 4 down vote accepted
sed s/^root.*/root:\ someuser@gmail.com/ -i /etc/aliases && newaliases

Run as root. Will alias the delivery address for root to the email address of your choice. Otherwise, manually edit /etc/aliases and modify the root's alias in the form of: root: someuser@some.mail.host to have root's e-mails automatically forwarded to that address. For more information on the /etc/aliases file, man aliases

share|improve this answer
1  
And you need an MTA which is able to send mail to "the outside world". This does not work with only a MDA. –  mailq Aug 16 '11 at 15:09
1  
@mailq: Please elaborate –  Dan Esparza Aug 16 '11 at 15:13
    
Correct me if I'm wrong, but this has the effect of setting the line root: someuser@gmail.com in the /etc/aliases file and then running 'newaliases'. –  Dan Esparza Aug 16 '11 at 15:18
2  
@Dan That is correct. \@OG: One should be nice provide clear instructions rather than shell golf scripts. –  Jeff Ferland Aug 16 '11 at 15:24
1  
On a stripped down server one could have only a MDA which can only deliver to local mailboxes. Or a "real" MTA which acts as SMTP client, SMTP server, MDA and maybe even more. –  mailq Aug 16 '11 at 15:24

The difference between having your mail address in .forward and in /etc/aliases is that, if you use .forward, the mail will first land in your local mailbox (possibly /var/spool/mail/root by default) and then a copy will get forwarded to you. In the /etc/aliases way, however, it will get sent directly to you, without any local delivery. You might want to consider this while choosing the method, whether you want a local copy to remain on server or not.

share|improve this answer
    
This is of course valid in case you have a proper MTA, otherwise, the other answers are more relevant as /etc/aliasas wont work for remote delivery. –  Tuncay Göncüoğlu Nov 30 '12 at 18:08

Another way is for forward root's mail.

echo "youraddress@domain.com" > /root/.forward

You'll need to make sure that sendmail/postfix is installed and running and that your host can connect to the SMTP servers for the receiving domain. Otherwise, you'll need to configure some host as a "smart host" to relay all of your mail.

To get the SMTP servers: nslookup -type=mx domain.com

To test connectivity: telnet <hostname> 25 or nc -z <hostname> 25

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.