I have server proxmox1 configured to send emails through GMail server. Here is the relevant part of my /etc/postfix/main.cf :
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = proxmox1
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = $myhostname, localhost.$mydomain, localhost
# p1 has an IP in the range 192.168.1.0/24
mynetworks = 127.0.0.0/8 192.168.1.0/24
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = ipv4
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_tls_security_level = encrypt
smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_sasl_security_options = noanonymous
I try to send email from server p1, using mailx and the postfix server on proxmox1. Here is my .mailrc file :
set smtp=smtp://proxmox1
set from="[email protected](p1)"
And here is the command I use :
echo "Test message" | mailx -s "important mail" [email protected]
It fails because postfix on proxmox1 tries to connect on port 25 to various google mail servers (/var/log/mail.log on proxmox1) :
Apr 22 11:45:00 p1 postfix/smtp[6888]: connect to aspmx.l.google.com[142.250.27.26]:25: Connection timed out
Apr 22 11:45:30 p1 postfix/smtp[6888]: connect to alt2.aspmx.l.google.com[142.250.150.27]:25: Connection timed out
Apr 22 11:45:30 p1 postfix/smtp[6888]: connect to alt1.aspmx.l.google.com[2a00:1450:4025:c03::1a]:25: Cannot assign requested address
Apr 22 11:45:30 p1 postfix/smtp[6888]: connect to alt2.aspmx.l.google.com[2a00:1450:4010:c1c::1b]:25: Cannot assign requested address
Apr 22 11:45:30 p1 postfix/smtp[6888]: D331827596: to=<[email protected]>, relay=none, delay=179091, delays=179031/0.01/60/0, dsn=4.4.1, status=deferred (connect to alt2.aspmx.l.google.com[2a00:1450:4010:c1c::1b]:25: Cannot assign requested address)
The same command on proxmox1 gives a different log :
Apr 22 12:03:38 proxmox1 postfix/pickup[280663]: 87E1211695: uid=0 from=<root>
Apr 22 12:03:38 proxmox1 postfix/cleanup[340498]: 87E1211695: message-id=<20230422100338.87E1211695@A>
Apr 22 12:03:38 proxmox1 postfix/qmgr[280664]: 87E1211695: from=<root@A>, size=420, nrcpt=1 (queue active)
Apr 22 12:03:40 proxmox1 postfix/smtp[340500]: 87E1211695: to=<[email protected]>, relay=smtp.gmail.com[142.250.102.109]:587, delay=2.2, delays=0.1/0.11/0.75/1.2, dsn=2.0.0, status=sent (250 2.0.0 OK 1682157820 u13-20020a170906c40d00b0094aa087578csm3131703ejz.171 - gsmtp)
Apr 22 12:03:40 proxmox1 postfix/qmgr[280664]: 87E1211695: removed
It looks like the relay_host
option is ignored when sending email from p1...
Any idea ?
Marc