I am using Ubuntu 22.04 LTS and Postfix to send messages out through SendGrid. I followed the tutorial at here https://www.twilio.com/docs/sendgrid/for-developers/sending-email/postfix
I have several VPS's and I use nicknames to keep them separate in my head - this one I named COCONUT. Some messages are going out if the from
address is spelled out, but all system messages fail to send. When sending a ps -ely | mailx -s Testing [email protected]
, it tries to send from from=<root@coconut>
I get the error because SendGrid knows I do not have permissions from just "coconut" hence the sender's identity error.
log entries from /var/log/mail.log
when running a ps -ely | mailx -s Testing [email protected]
...
Jul 19 09:28:57 coconut postfix/pickup[624347]: 290E754988: uid=0 from=<root@coconut>
Jul 19 09:28:57 coconut postfix/cleanup[624480]: 290E754988: message-id=<[email protected]>
Jul 19 09:28:57 coconut postfix/qmgr[624348]: 290E754988: from=<root@coconut>, size=17599, nrcpt=1 (queue active)
Jul 19 09:28:57 coconut postfix/smtp[624482]: 290E754988: to=<[email protected]>, relay=smtp.sendgrid.net[44.239.172.8]:587, delay=0.83, delays=0.01/0.01/0.6/0.2, dsn=5.0.0, status=bounced (host smtp.sendgrid.net[44.239.172.8] said: 550 The from address does not match a verified Sender Identity. Mail cannot be sent until this error is resolved. Visit https://sendgrid.com/docs/for-developers/sending-email/sender-identity/ to see the Sender Identity requirements (in reply to end of DATA command))
Jul 19 09:28:57 coconut postfix/cleanup[624480]: F2DC254989: message-id=<[email protected]>
Jul 19 09:28:57 coconut postfix/bounce[624483]: 290E754988: sender non-delivery notification: F2DC254989
Jul 19 09:28:57 coconut postfix/qmgr[624348]: F2DC254989: from=<>, size=20071, nrcpt=1 (queue active)
Jul 19 09:28:57 coconut postfix/qmgr[624348]: 290E754988: removed
...
Here is my /etc/postfix/main.cf
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname
myhostname = coconut.example.com
myorigin = example.com
mydestination = $myhostname, localhost #added to no effect
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h
readme_directory = no
# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on
# fresh installs.
compatibility_level = 2
#header_checks = regexp:/etc/postfix/my_custom_header
inet_protocols = ipv4
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_security_level = encrypt
header_size_limit = 4096000
relayhost = [smtp.sendgrid.net]:587
Here is the contents of my /etc/mailname
example.com
Here is the contents of my /etc/hostname
coconut.example.com
Any ideas on how to fix the system emails as being sent from root@coconut?
You could use Postfix's
canonical_maps
with canonical(5) maps.Add setting
canonical_maps = hash:/etc/postfix/canonical
Create
/etc/postfix/canonical
containing, e.g.,As the lookup table type is Berkeley DB (
hash
),you need to use this after any modifications to the file:
Reload Postfix.
The system should now rewrite
root@coconut
as canonical[email protected]
.