Using Exim4 to send Messages through GMail

Debian ships default with Exim4 as a mail server. To use this to send messages through Google's smtp servers for GMail accounts, you need to do the following.

# dpkg-reconfigure exim4-config

Run

# editor /etc/exim4/passwd.client

and add the following lines:

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

Run

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

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, Exim 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 using this login / password.

For specifying outgoing port other than 25, you can configure it via debconf with smtp.gmail.com::587 (This is for etch and later).

Add your outgoing email-address to the /etc/exim4/email-addresses

# echo 'YOUR-USER-NAME@LocalHost: yourAccountName@gmail.com' >> /etc/exim4/email-addresses

Finally for all versions of Debian, run

# update-exim4.conf

Good luck.

Possible Problems

If nothing seems to happen examine your /etc/exim4/ directory, for /etc/exim4/exim4.conf.
Exim will use this file if it exists and ignore the autogenerated one, see UPDATE-EXIM4.CONF(8).
You'd may rename this file to enable /var/lib/exim4/config.autogenerated and see what effect this may have. But you should check where this file has come from and contact its originator(s).

If this doesn't work, first enable POP for your GMail account, and then try:

# tail /var/log/exim4/mainlog

.

If you see something like

2005-10-23 21:51:04 1ETuIW-0002iB-Qo ** 
yourAccountName@gmail.com R=smarthost
T=remote_smtp_smarthost: SMTP error from remote mailer after
MAIL FROM:<yourAccountName@gmail.com> SIZE=1555:
host gmail-smtp.l.google.com [64.233.163.111]: 530
5.7.0 Authentication Required 23sm863650nzn

except there is something different than

gmail-smtp.l.google.com

,

the host might be resolving to something else. In that case, replace the gmail-smtp.l.google.com in your /etc/exim4/passwd.client with whatever it says.

To try test these changes immediately---you might have failed enough times to have a very long delay between retries---run

# exim4 -M 1ETuIW-0002iB-Qo

or

# exim -v -M 1K3x0N-0000cb-Fq 2>&1 | less

but replacing that garbage ID tag from the first line of the error entry in the log file with the ID of the failed message that you want to resend.

exim4 4.62-2, the default version for ubuntu Edgy has authentication problems. Bug report 403583 shows required changes to the hosts_try_auth clause of /etc/exim4/conf.d/transport/30_exim4-config_remote_smtp_smarthost.

If you see something like

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

exim is unable to read the password file.

The following will restore the default permissions.

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

If you see in mainlog message that states "Credentials Rejected", type:

# vi /etc/exim4/passwd.client

and replace every yourAccountName@gmail.com with yourAccountName (delete @gmail).