18 June 2016

Ubuntu: Forward System Email

If you want to forward system emails to a real email address:
Run all commands as sudo -i
Replace email@example.com with your destination email.
  1. Install Sebndmail:
    sudo apt-get install sendmail
  2. Make sure the last line of /etc/aliases is: root: email@example.com
    vi /etc/aliases
  3. Get the hostname:
  4. Add the hostname to genericsdomain
    cd /etc/mail
    vi genericsdomain
  5. Map your local user name to recipient email e.g.:
    vi genericstable
    [username]@[hostname] email@example.com
  6. Add your username as a trusted user:
    vi trusted-users
  7. To prevent long DNS timeouts each time sendmail restarts or tries to send an email add "localhost.localdomain " to # localhost, for example:
    vi /etc/hosts localhost localhost.localdomain [hostname]
  8. Edit sendmail to add before the line "MAILER_DEFINITIONS":
    vi sendmail.mc
    dnl #
    dnl FEATURE(`allmasquerade')
    dnl FEATURE(`masquerade_envelope')
    dnl # 
  9. Rebuild and reload the sendmail config:
    /etc/init.d/sendmail reload sendmailconfig 
  10. Now you should be able to email yourself:
    apt install mailutils
    echo "test" | mail --debug-level=15 -s "test email" email@example.com

No comments:

Post a Comment