Today I read that Postfix can be better than sendmail and found a great Russian article on how to configure Postfix to work with Yandex.ru relay (Yandex.ru is some kind of Russian Google). The only notice I would give is that in a Docker container I need also install rsyslog, otherwise /var/log/mail.log file is not created:
apt install rsyslog
After doing all the steps described in this Russian manual I was able to send email to Yandex.ru and GMail accounts, but GMail landed all the emails to its spam folder. My first idea was that it is because I did not configure ‘from address’ correctly, so I had the following in /var/log/mail.log, and also there was a message ‘Cannot assign requested address‘:
Oct 27 11:36:19 0675c97b78aa postfix/pickup: 8C7ECE5B72: uid=0 from=<root>
Oct 27 11:36:19 0675c97b78aa postfix/cleanup: 8C7ECE5B72: message-id=<20171027113619.8C7ECE5B72@0675c97b78aa.localdomain>
Oct 27 11:36:19 0675c97b78aa postfix/qmgr: 8C7ECE5B72: from=<firstname.lastname@example.org>, size=405, nrcpt=2 (queue active)
Oct 27 11:36:19 0675c97b78aa postfix/smtp: connect to gmail-smtp-in.l.google.com[2a00:1450:400c:c09::1b]:25: Cannot assign requested address
Previously I published post How I configured sendmail for PHP on Ubuntu Server 12.04 describing how to configure sendmail to use custom SMTP server. But after switching to Ubuntu 16.04 VPS my first idea was that I can use sendmail in its default configuration, but this idea was wrong, because while sendmail worked well with yandex.ru (some Russian mail server), for example, it did not work with GMail, because GMail did not accept the mail reporting ‘DSN: Service unavailable.‘ in /var/log/mail.log, see my post on Ubuntu Forum for more information. Now my second idea is that using GMail as sendmail relay will prevent GMail from rejecting my mail. Below I provided a short instruction on how to realize this successful idea.
Install the packages
apt-get install sendmail mailutils
mailutils allows to run mail command.
Preventing sendmail from been very slow
The first thing that I did after installing sendmail with
aptitude install sendmail
is I put “gate.localhost” (gate is my server name) to /etc/hosts so it looks like this:
127.0.0.1 localhost.localdomain localhost
127.0.1.1 gate.localhost gate
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
With default /etc/hosts containing only “gate” and “localhost” sendmail hangs up for a while and writes to /var/log/mail.log the following message:
My unqualified host name (gate) unknown; sleeping for retry.