Setup Exim4 to use Gmail as an external SMTP server:
# dpkg-reconfigure exim4-config
Choose the answers:
Enable 2-factor authentication on your Gmail account used for sending emails and follow Google instruction to create app specific password.
Edit /etc/exim4/passwd.client
and add the following line inside:
smtp.gmail.com:<gmail-sender-account-name>:<your-app-password>
You should use account name not email address here.
If it is new or restored file then ensure the permissions are correct:
# chown root:Debian-exim /etc/exim4/passwd.client
# chmod 640 /etc/exim4/passwd.client
You can also configure replacement of the local sender address to your Gmail one:
# echo '<local-user-name>: <gmail-sender-account-name>@gmail.com' >> /etc/email-addresses
# echo '<local-user-name>@localhost: <gmail-sender-account-name>@gmail.com' >> /etc/email-addresses
# echo '<local-user-name>@<hostname>: <gmail-sender-account-name>@gmail.com' >> /etc/email-addresses
Update Exim4 configuration, remove stale mail:
# update-exim4.conf
# invoke-rc.d exim4 restart
# exim4 -qff
Check that email is sent using:
$ echo "Subj" | mail -s "Test email from Exim4" <email-address>
Check logs to see if email was sent successfully:
# less /var/log/exim4/mainlog
Check if email is received by <email-address>
. If it is Gmail address you may
need add filtering rule to prevent email be classified as a spam.
In order to redirect the local mail to the external address, edit the
/etc/aliases
file and add the following line:
<local-user-name>: <email-address>
and execute:
$ newaliases
in order to update aliases configuration.
Links: