doom'd net

still mucking around with the ol'computer


Using Sendmail to forward to either gmail or iCloud

Configuring sendmail to use either gmail or iCloud as a mail forwarder has a lot of nice advantages.

For example, you can forward root email to your personal email, run your own email server. Or even go old school and use pine or elm for your email client. I use it to run my own email server and to email status from monitoring scripts.

It’s not particularly hard either, but it does require a few dependency packages and a little configuration.

On Redhat based systems such as Fedora and Centos, you’ll need 5 packages:

  • sendmail
  • sendmail-cf
  • m4
  • make
  • cyrus-sasl-plain

NOTE: the last one is VERY important, without it, sendmail will NOT send email, and it will take you forever to figure it out!  There are probably other dependencies, but dnf or yum will take care of them.

Once you have those, in /etc/mail, you’ll need to edit sendmail.mc and add, or comment in and edit to match,

for iCloud:

define(`SMART_HOST',`smtp.me.com')dnl

for gmail:

define(`SMART_HOST',`smtp.gmail.com')dnl

for either:

define(`RELAY_MAILER',`esmtp')dnl
define(`RELAY_MAILER_ARGS',`TCP $h 587')dnl
FEATURE(authinfo)dnl

EXPOSED_USER(`root')dnl
FEATURE(masquerade_envelope)dnl
FEATURE(genericstable,`hash -o /etc/mail/genericstable')dnl
GENERICS_DOMAIN_FILE(`/etc/mail/genericsdomain')dnl

Create a file called genericstable with one entry per line that maps your local user with your iCloud or gmail email address.

Some example entries:

root: user@icloud.com
backuppc: user@gmail.com
dwalker: user@gmail.com

Create a file called authinfo that contains an for which one you need for which service you’re using:

AuthInfo:smtp.me.com "U:icloud_name" "P:password" "M:PLAIN"
AuthInfo:smtp.gmail.com "U:gmail_name" "P:password" "M:PLAIN"

Obviously, change your icloud_name, or gmail_name to your login for which ever service your going to us, and password to your password for that service.  It doesn’t hurt to have both entries in that file if you have accounts on both, but sendmail will use which ever one is specified in sendmail.mc as the SMART_HOST.

That’s it! Now run make while in /etc/mail, and it will build your config files with m4.  Then add any entries in /etc/alias, for example to send root and your local account emails to you gmail account.

Finally restart sendmail and test:

echo "testing from $(hostname) on $(date)" | mail -s "testing 001" root