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?

link|improve this question
feedback

2 Answers

up vote 3 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

link|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
1  
@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
show 1 more comment
feedback

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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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