Linux Home

(Last updated: Tuesday, April 17, 2007)

Linux, Sendmail and

Last updated: Sunday, Nov. 13, 2009

Update: I'm moving my home server over to Centos 5.4 and things are a little different.

Update: I corrected a missing <TMPF> option in the hash command below. Sorry about that.

Found a few more links on the subject which may help others trying to get sendmail working with Gmail.

Some folks may be interested in using Postfix instead of sendmail. For those there are sites such as Soup to nuts - Postfix tutorial.

I found this, on Sendmail, Fetchmail and Google Mail, in Yan Li's blog: Yan Li's Words. Yan Li has a simplified setup (I did a few more things as I wanted to fix a few email problems). More importantly he has the config for setting up fetchmail to get user mail from Google Mail. Careful, he does come back to this page for a portion of the setup.

A work in progress but I actually have this working properly. I started by searching the internet with Google and found only one link that was partially useful. That link, in Portuguese, is appropriately called Sendmail + SMTP GMAIL. Unfortunately the direct instructions didn't work. So I decided to clean up the file that was supplied and throw in a few changes that had worked for me with my Linux, Sendmail and setup. After double checking various settings (must have been a spelling error) I got my Linux box to work with Sendmail.

There are things to check and lots of little configuration changes to make. Before you start wondering why are you going through this exercise remember that with power comes responsibilty. Sendmail is very power. So lets start with the files you will need to change:

  • /etc/mail/
  • /etc/mail/auth/client-info

This is where the files are on my Linux box. There is no /etc/mail/auth directory yet on either my FC6 or Centos box, so I'll create one later. A word of warning, I'm not sure I have everything working properly just yet. I am able to send out email from my machine but I haven't fully checked the headers to see that everything is correct. Also because I have so many copies of sendmail configs lying around I'll post my entire (FC6) file::

    dnl# This is the default sendmail .mc file for Slackware. To generate
    dnl# the file from this (perhaps after making some changes),
    dnl# use the m4 files in /usr/share/sendmail/cf like this:
    dnl# cp /usr/share/sendmail/cf/
    dnl# cd /usr/share/sendmail/cf
    dnl# sh Build
    dnl# You may then install the resulting .cf file:
    dnl# cp /etc/mail/
    dnl# This is where it is on my box, you're box might differ
    VERSIONID(`Linux Home Automation FC6 Gmail')dnl
    dnl# These settings help protect against people verifying email addresses
    dnl# at your site in order to send you email that you probably don't want:
    define(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun')dnl
    dnl# No timeout for ident:
    define(`confTO_IDENT', `0')dnl
    dnl# Enable the line below to use smrsh to restrict what sendmail can run:
    dnl FEATURE(`smrsh',`/usr/sbin/smrsh')dnl
    dnl# See the README in /usr/share/sendmail/cf for a ton of information on
    dnl# how these options work:
    dnl# FEATURE(masquerade_envelope)
    FEATURE(`mailertable',`hash -o /etc/mail/mailertable.db')dnl
    FEATURE(`virtusertable',`hash -o /etc/mail/virtusertable.db')dnl
    FEATURE(`access_db', `hash -T<TMPF> /etc/mail/access')dnl
    FEATURE(`local_procmail',`',`procmail -t -Y -a $h -d $u')dnl
    dnl# Turn this feature on if you don't always have DNS, or enjoy junk mail:
    dnl# FEATURE(`accept_unresolvable_domains')dnl
    FEATURE(`authinfo',`hash /etc/mail/auth/client-info')dnl
    dnl# Also accept mail for localhost.localdomain:
    define(`RELAY_MAILER_ARGS', `TCP $h 587')
    define(`ESMTP_MAILER_ARGS', `TCP $h 587')
    define(`CERT_DIR', `MAIL_SETTINGS_DIR`'certs')dnl
    define(`confCACERT_PATH', `CERT_DIR')dnl
    define(`confCACERT', `CERT_DIR/CAcert.pem')dnl
    define(`confSERVER_CERT', `CERT_DIR/mycert.pem')dnl
    define(`confSERVER_KEY', `CERT_DIR/mykey.pem')dnl
    define(`confCLIENT_CERT', `CERT_DIR/mycert.pem')dnl
    define(`confCLIENT_KEY', `CERT_DIR/mykey.pem')dnl
    dnl #
    dnl # masquerade not just the headers, but the envelope as well
    dnl #
    dnl #
    dnl # masquerade not just, but @* as well
    dnl #
    dnl #
    MASQUERADE_AS(`') dnl               
    FEATURE(genericstable, `hash -o /etc/mail/genericstable') dnl
    dnl #
    dnl # Leave these at the end, sendmail prefers these last (for the most part)
    dnl #

Remember to change the to your appropriate FQDN host. If you're not already familiar with the various redirector services check out DynDNS Inc.. There are others so do your homework. I use the free service and I've been very happy with it.

Note: My Centos file looks different from the above FC6 file. For one thing the placement of the lines differs. For another the Centos supports IPV6. I'll post that at a later date once I get it working properly.

Later I'll explain the virtusertable and mailertable entries. I needed all of that so other devices throughout my network can send email to my local machines or to users on the internet.

Changes I made to /etc/mail/ (added to the end of the file):

    FEATURE(`msp', `[]')dnl

If you don't have an /etc/mail/auth directory, as root, create one like this:

    # mkdir -p /etc/mail/auth
    # chmod 700 /etc/mail/auth

You won't have the next client-info files so you'll have to create it (with you favorite Unix editor). Change the permissions on the client-info file like this:

    # chmod 600 client-info

So using my email ID and password I made the following entry in /etc/mail/auth/client-info:

    # cat /etc/mail/auth/client-info "U:smmsp" "I:user_id" "P:password" "M:PLAIN" "U:smmsp" "I:user_id" "P:password" "M:PLAIN"

Yes, password is plain text. It is possible to encode the password but I don't have those instructions here.

Remember to replace user_id with your Gmail email ID (your email addresse without the and password with your email password. Also make sure that the client-info file has tight permissions so nobody can read your password.

How to compile it into a db file:

    # cd /etc/mail/auth
    # makemap -r hash client-info.db < client-info

And finally make sure your running the latest cf files since your mc file changes:

    # cd /etc/mail
    # make

If you don't have a Makefile in your /etc/mail directory then you'll need to rebuild your files manually. Here's an example using

   # m4 >

And lastly restart sendmail:

    # service sendmail restart

Changing the sender on outgoing email

One of the things I wanted to do was to correct the sender's email address that was being used on outgoing email. I frequently have processes that send email and run as 'other' users on my server. What I'd like to see is instead of this:

  • cookie!cookie!

I'd rather see this:


That way if the mail ends up in the wrong place at least the person can reply and let me know that my mail was accidently received by them. The good news is that it's not hard to do with Sendmail. Just add these lines to your /etc/mail/ file:


Now edit the /etc/mail/genericsdomain file and add the entries you want changed, like this:


Now compile it into a db file:

    # cd /etc/mail
    # makemap -r hash genericstable.db < genericstable

And finally make sure your running the latest cf files since your mc file changes:

    # cd /etc/mail
    # make

And lastly restart sendmail:

    # service restart sendmail