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.

It’s not particularly hard either, but it does require some configuration work.  On Redhat based systems such as Fedora and Centos, you’ll need 5 packages:

  1. sendmail
  2. sendmail-cf
  3. m3
  4. make
  5. 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 and add,  or comment in and edit to match,

for iCloud:

define(`SMART_HOST’, `’)dnl

for gmail:

define(`SMART_HOST’, `’)dnl

for either:

define(`RELAY_MAILER_ARGS’, `TCP $h 587′)dnl

FEATURE(genericstable, `hash -o /etc/mail/genericstable’)

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:


Create a file called authinfo that contains an for which one you need for which service you’re using: “U:icloud_name” “P:password” “M:PLAIN” “U:gmail_name” “P:password” “M:PLAIN”

Obviously, change your icoud_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 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

Leave a Reply

Your email address will not be published. Required fields are marked *