Primary Information Sources

<!> Check Gmail service site with key word like "gmail configuring other mail clients" for new configuration requirement changes.

<!> Please read Debian Exim4 User FAQ first.

PkgExim4UserFAQ is updated by the exim4 maintainer. It should be more current and reliable than this page. "Section 10.1" on PkgExim4UserFAQ as of January 2012 mentions problems of this page. People updated this wiki page after that comment tried to address problems as much as possible. If you still find any errors, please login to edit this page to correct it.

This wiki page is only a secondary information.

Mail Address Basics

Due to pervasive SPAM problem, most SMTP services including Gmail checks legitimacy of mail messages while delivering them. Email address rewriting as discussed here may cause such SMTP services to filter your mail as illegitimate one and drop it quietly. Understanding of the difference between the mail envelope address and the mail "From: " address is essential to minimize such risks. Be careful about this problem since situation changes all the time.

Known Limitations of Gmail

If you send a mail to a mailing list via a SMTP server provided by Gmail, the returned mail message from the mailing list is treated as **read** by the Gmail POP3 service and it may not be downloaded to your local mail client by the mail remote mail retrieval and forwarding utility such as fetchmail/getmail/... . (This is true even if your visible receiving mail address in the "To: " field is one with non-Gmail mail forwarding service as long as it is forwarded to the Gmail account you used to send the mail.)

Recently, Gmail started to rewrite both envelope and header addresses to the email address of your account automatically if you use their SMTP smarthost while providing DKIM signiture added to your mail. So there is no nore point making complicated mangling of email address if you use gmail.

If you still wish to receive mail with some forwarding address such as foo-guest@alioth.debian.org, you need to use non-Gmail SMTP service such as one provided by your connection ISP providing IP connectivity to you.

Using Exim4 to Send Messages through GMail

<!> GMail is said to have limit of 100 messages/day/account when you use it to send mails via its SMTP service. Keep this in mind :)

Debian ships default with Exim4 as a mail server. You can configure this Exim4 to use the Google's SMTP servers as its smarthost using your GMail account.

Let's assume:

(If you have a real DNS resolvable IP address, the 127.0.1.1 line of /etc/hosts should not exist but should have one for that IP address.)

Initial configuration of Exim4 is invoked with:

# dpkg-reconfigure exim4-config

This setting is for a typical desktop PC which has no resolvable host name. If you wish to do something more such as relaying mail, you need to configure this accordingly.

Submission port 587 on Gmail stystem uses STARTTLS service to ensure secure password protection.

(For servers with a real DNS resolvable host name, set it accordingly. But why are you bothering to set up smarthost to use gmail? I see no good reason to do this.)

Configuration of Exim4 for SMTP authentication uses the canonical host name.

Gmail provide the SMTP service using server at smtp.gmail.com . Get the canonical host names of such servers by running:

$ host smtp.gmail.com
smtp.gmail.com is an alias for gmail-smtp-msa.l.google.com.
gmail-smtp-msa.l.google.com has address 74.125.127.109
gmail-smtp-msa.l.google.com has address 74.125.127.108

So gamil*.google.com matches all host names.

The configure of your Exim4 to use the external SMTP service such as Gmail is stored in the /etc/exim4/passwd.client file. Run

# editor /etc/exim4/passwd.client

and add the following lines:

*.google.com:SMTPAccountName@gmail.com:y0uRpaSsw0RD

Here's how /etc/exim4/passwd.client works: the first field in this file is matched against the reverse DNS lookup of the remote smtp server (in this case GMail). In other words, Exim4 will do a DNS query to get the IP address of smtp.gmail.com, and then it will do a reverse DNS query to get the domain name of this IP (similar to the result of running "$ host smtp.gmail.com"). If this domain name (or IP, if the server IP doesn't have a reverse domain name configured) matches the first field of this file, it will try to authenticate for SMTP using this login / password.

If you restored /etc/exim4/passwd.client from the backup file, please make sure to restore its file ownership and permissions with

# chown root:Debian-exim /etc/exim4/passwd.client
# chmod 640 /etc/exim4/passwd.client

Edit your address rewrite table /etc/email-addresses by running:

# echo 'YOUR-USER-NAME: SMTPAccountName@gmail.com' >> /etc/email-addresses
# echo 'YOUR-USER-NAME@localhost: SMTPAccountName@gmail.com' >> /etc/email-addresses
# echo 'YOUR-USER-NAME@hostname1: SMTPAccountName@gmail.com' >> /etc/email-addresses
# echo 'YOUR-USER-NAME@hostname1.localdomain: SMTPAccountName@gmail.com' >> /etc/email-addresses

(Actually, recent Gmail rewrites source address automatically anyway. So you do not need to do the above. But Gmail may change again. This is still valid work needed for other smart host setting. So I keep it as is now.)

If any messages comes to your Exim4 with different envelope addresses, you need to list them too.

(Although choosing "YES" for "Hide local mail name in outgoing mail?" may allow you to avoid this trouble, you risk sending unintended mails such as ones to "root" to smarthost.)

Finally, run

# update-exim4.conf
# invoke-rc.d exim4 restart
# exim4 -qff

This 3 step process ensures to update the Exim4 configuration, to reload it, and to force a delivery attempt for all messages including frozen ones.

See "man update-exim4.conf" for more on Exim4 configuration.

Verification of Configuration Results and Trouble Shootings

After the configuration, please verify your configuration result with

# tail /var/log/exim4/mainlog

If you start receiving SMTP authentication errors in mainlog messages, run

$ host smtp.gmail.com
smtp.gmail.com is an alias for gmail-smtp-msa.l.google.com.
gmail-smtp-msa.l.google.com has address 74.125.127.109
gmail-smtp-msa.l.google.com has address 74.125.127.108

to verify the resolving host names all match with the definition in your /etc/exim4/passwd.client. Gmail may have changed its host name naming scheme.

If you see in mainlog messages that state something like

failed to open /etc/exim4/passwd.client for linear search:
Permission denied (euid=102 egid=102)

you have some file permission problems. Please restore the default permissions as in the case mentioned for the backup file described above. (euid and egid may be different on your installation.)

If you see in mainlog messages that state "Credentials Rejected", you have mail account or password problem. Please update your account name password in the /etc/exim4/passwd.client file.

Although most ISP's account name does not include "@isp-name.com" part, Gmail requires it.

Hint for SMTP service with SSL (Yahoo)

Although STARTTLS service on port 587 was supported, deprecated SMTPS protocol (SSL on port 465) was not supported by older Exim as a client.

Debian wheezy system comes with Exim 4.77 and it support SMTPS. So non-Gmail server such as Yahoo can be used safely.

You need to edit system configuration 30_exim4-config_remote_smtp_smarthost in /etc/exim4/conf.d/transport to add "protocol=smtps". (A bit intrusive change ... if you have better suggestion, please update this.) See 656841

See http://www.exim.org/exim-html-current/doc/html/spec_html/ch30.html under "4. Private options for smtp" on "protocol".

Hint for using multiple smarthosts depending on your header From: addreses

If you wish to use multiple smarthosts depending on your header From: addreses, you can edit your /etc/exim4/conf.d contents.

I have made a example of it and submitted to exim4-config as wishlist bug report. If you wish to use this type of configuration, you just need to make the same content as the patch in /etc/exim4/conf.d/ and add a file in /etc/exim4/conf.d/rewrite/ with a line

ENABLE_MULTIPLE_SMARTHOSTS = yes"

See 656841

Hints for setting mutt for multiple From: addresses

If you wish to deploy use a different visible e-mail addresses in the "From :" message header field, you need to set it by mail clients generation mail messages such as mutt etc.

Here is an example of .muttrc:

alternates "foo\.bar@gmail\.com|bar\.foo@gmail\.com|foo_bar@example\.com|foobar@debian\.org"

macro compose "1" "<edit-from>^UFoo Bar \<foobar@debian.org\>\n"
macro compose "2" "<edit-from>^UFoo Bar \<foo.bar@gmail.com\>\n"
macro compose "3" "<edit-from>^UFoo Bar \<bar.foo@gmail.com\>\n"
macro compose "4" "<edit-from>^UFoo Bar \<foo_bar@example.com\>\n"