Score:1

For smtp relay, what is required for postfix to authenticate to gmail's smtp server?

cn flag

I build websites within a private home-office network.

Locally hosted website are development versions of sites that I build for clients. I want the websites that I am building to be able to send emails. And I want to test email capability from the local development versions of the sites within my office network.

My dev server is running Ubuntu 22.04

I am configuring postfix as a send-only server. I'd like to use gmails smtp service as a relay.

This is what I have done so far:

  • In my Google admin, I have enabled less secure apps. (I'm aware that they are phasing this out for some users, but I'm a Google Workspace user and I believe that 'less secure apps' will continue to work for us. Do tell me if I'm wrong.)

  • I've put my credentials in /etc/sasl_password in this format:

[smtp.gmail.com]:587 myemailaddress@mydomain:mypassword

  • I've edited /etc/postfix/main.conf to include these lines:
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
  • I've used the 'postmap' command to add the password file to postmap's database: postmap /etc/postfix/sasl_passwd

  • When I run 'postfix check' there is no return. No errors or warnings (or anything else) are displayed.

  • I've restarted the postfix server

After restarting I send a test mail from one of my development sites.

The mail log tells me that mail has been refused because of an authentication failure. The relevant line is:

status=deferred (SASL authentication failed; cannot authenticate to server smtp.gmail.com[142.251.10.109]: invalid parameter supplied)

What am I missing?

anx avatar
fr flag
anx
Add `-v` to your `smtp` (client) service in `master.cf` to produce [more verbose](https://www.postfix.org/DEBUG_README.html#verbose) logs.
anx avatar
fr flag
anx
There is a typo in your `postmap` call in your question.. verify that the password map in use was actually processed by calling `postmap -q "[smtp.gmail.com]:587" hash:/etc/postfix/sasl_passwd`
bob.dobbs avatar
cn flag
Thanks @anx. Typo corrected. The postmap command appears to confirm that the password map was used: the type was in the serverfault description only and not in my conf file. I've added the '-v' flag to smtp in master.cf, but after that edit the error is no more detailed.
anx avatar
fr flag
anx
The `-v` flag should give you quite a bit more context in logs. If it does not, check whether you added it to the relevant line (smtp, not smtpd), and restart postfix to apply it right away.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.