I'm new to server admin and try ty send emails from my server with a GSUITE user as sender
I read a LOT of tutorials (including Configure postfix to use Google Apps SMTP relay in a Google Compute Engine instance) but I'm lost in all those concepts of EHLO / TLS / …
I just want to :
- send email from server :
- hosted at MY_HOST_NAME.COM
- with ip address MY_HOST_IP
- with host name MY_HOST_NAME
- using gsuite domain MY_GSUITE_DOMAIN.COM
So far I have :
- Entered my SMTP credentials in /etc/postfix/sasl/sasl_passwd and generated a sasl_passwd.db file
- Configured Gsuite SMTP relay options following google doc
- to allow users from my Gsuite domain
- to require smtp authentication
- NOT to require TLS authentication
My postfix config /etc/postifx/main.cf is as following :
myorigin = /etc/mailname ## FILE CONTAINS ONLY MY_HOST_NAME
biff = no
readme_directory = no
compatibility_level = 2
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd
myhostname = MY_HOST_NAME.COM
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = $myhostname, MY_GSUITE_DOMAIN.COM, localhost
fallback_transport = relay
relayhost = [smtp-relay.gmail.com]:587
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
inet_protocols = ipv4
I try to send a test email using sendmail command :
echo "Subject: sendmail test " | sendmail -v john@johncompany.com
… and keep getting the same error in /var/log/mail.log :
Sep 19 11:06:18 MY_HOST_NAME postfix/pickup[22443]: B40A61D4FD0: uid=0 from=<root>
Sep 19 11:06:18 MY_HOST_NAME postfix/cleanup[9353]: B40A61D4FD0: message-id=<20190919090618.B40A61D4FD0@**MY_SERVER_HOST.COM**>
Sep 19 11:06:18 MY_HOST_NAME postfix/qmgr[22444]: B40A61D4FD0: from=<root@**MY_GSUITE_DOMAIN.COM**>, size=275, nrcpt=1 (queue active)
Sep 19 11:06:18 MY_HOST_NAME postfix/smtp[9355]: B40A61D4FD0: to=<JOHN@JOHNCOMPANY.COM>, relay=smtp-relay.gmail.com[173.194.76.28]:587,
delay=0.23, delays=0.03/0.01/0.08/0.11, dsn=5.7.1, status=bounced
(host smtp-relay.gmail.com[173.194.76.28] said: 550-5.7.1 Invalid credentials for relay [**MY_SERVER_IP**].
The IP address you've 550-5.7.1 registered in your G Suite SMTP Relay service doesn't match domain of 550-5.7.1
the account this email is being sent from. If you are trying to relay 550-5.7.1 mail from a domain that isn't
registered under your G Suite account 550-5.7.1 or has empty envelope-from, you must configure your mail
server 550-5.7.1 either to use SMTP AUTH to identify the sending domain or to present 550-5.7.1 one of your
domain names in the HELO or EHLO command. For more 550-5.7.1 information, please visit 550 5.7.1
https://support.google.com/a/answer/6140680#invalidcred d13sm115728wrp.67 - gsmtp (in reply to MAIL FROM command))
Sep 19 11:06:18 MY_HOST_NAME postfix/cleanup[9353]: EE3691D4FD2: message-id=<20190919090618.EE3691D4FD2@**MY_SERVER_HOST.COM**>
Sep 19 11:06:18 MY_HOST_NAME postfix/qmgr[22444]: EE3691D4FD2: from=<>, size=3661, nrcpt=1 (queue active)
Sep 19 11:06:18 MY_HOST_NAME postfix/bounce[9368]: B40A61D4FD0: sender non-delivery notification: EE3691D4FD2
Sep 19 11:06:18 MY_HOST_NAME postfix/cleanup[9353]: EF93A1D4FCA: message-id=<20190919090618.EF93A1D4FCA@**MY_SERVER_HOST.COM** >
Sep 19 11:06:18 MY_HOST_NAME postfix/bounce[9369]: B40A61D4FD0: sender delivery status notification: EF93A1D4FCA
Best Answer
The error was in the myorigin parameter : it has to be MY_GSUITE_DOMAIN.COM to have the right sender and not the host.
So google error was a bit misleading here.
Also dont forget to lower less secure apps in the gsuite account : https://support.google.com/a/answer/6260879?hl=fr
For those like me who want to send from gsuite email accounts with php, dont forget to :
... and debug using /var/log/mail.log or similar for your distro.
The best tutorial I found so far on the postfix / gsuite set-up is this one : https://www.linode.com/docs/email/postfix/configure-postfix-to-send-mail-using-gmail-and-google-apps-on-debian-or-ubuntu/
(I skipped the app password part)