如何从 postfix 存储 Gmail 的 sasl 密码?

如何从 postfix 存储 Gmail 的 sasl 密码?

后缀用于将邮件发送到本地主机或本地 FQDN,即主机名。通过 gmail 发送

nicholas@mordor:~$ 
nicholas@mordor:~$ swaks --to [email protected] --from [email protected]
=== Trying gmail.com:25...
*** Error connecting to gmail.com:25:
***     IO::Socket::INET6: connect: timeout
nicholas@mordor:~$ 
nicholas@mordor:~$ postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
compatibility_level = 3.6
inet_interfaces = all
inet_protocols = all
mailbox_size_limit = 0
maillog_file = /var/log/postfix.log
mydestination = $myhostname, mordor.saundersconsulting.tech, localhost
myhostname = mordor.saundersconsulting.tech
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
myorigin = mordor.saundersconsulting.tech
readme_directory = no
recipient_delimiter = +
relayhost = [smtp.gmail.com]:587
smtp_tls_CApath = /etc/ssl/certs
smtp_tls_security_level = may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_security_level = may
nicholas@mordor:~$ 
nicholas@mordor:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04 LTS
Release:    22.04
Codename:   jammy
nicholas@mordor:~$ 

日志:

Dec 16 14:56:11 mordor postfix/qmgr[1648523]: C78BE2BD4: from=<>, size=2244, nrcpt=1 (queue active)
Dec 16 14:56:11 mordor postfix/qmgr[1648523]: 639D92AC0: from=<>, size=2244, nrcpt=1 (queue active)
Dec 16 14:56:11 mordor postfix/smtp[1677087]: connect to smtp.gmail.com[2607:f8b0:400e:c03::6c]:587: Network is unreachable
Dec 16 14:56:12 mordor postfix/smtp[1677086]: C78BE2BD4: to=<[email protected]>, relay=smtp.gmail.com[74.125.199.109]:587, delay=4501, delays=4501/0.03/0.31/0.07, dsn=5.7.0, status=bounced (host smtp.gmail.com[74.125.199.109] said: 530-5.7.0 Authentication Required. For more information, go to 530 5.7.0  https://support.google.com/mail/?p=WantAuthError jc12-20020a17090325cc00b001d363e87759sm5602905plb.51 - gsmtp (in reply to MAIL FROM command))
Dec 16 14:56:12 mordor postfix/smtp[1677087]: 639D92AC0: to=<[email protected]>, relay=smtp.gmail.com[74.125.199.109]:587, delay=4502, delays=4501/0.03/0.31/0.07, dsn=5.7.0, status=bounced (host smtp.gmail.com[74.125.199.109] said: 530-5.7.0 Authentication Required. For more information, go to 530 5.7.0  https://support.google.com/mail/?p=WantAuthError u13-20020a170902e5cd00b001cff026df52sm16234005plf.221 - gsmtp (in reply to MAIL FROM command))
Dec 16 14:56:12 mordor postfix/qmgr[1648523]: C78BE2BD4: removed
Dec 16 14:56:12 mordor postfix/qmgr[1648523]: 639D92AC0: removed

对于使用“apps”密码的 Alpine 电子邮件客户端(原为 Pine),密码可以正常工作,该密码存储在 /etc/postfix/sasl/sasl_passwd 文件中。

Postfix 需要更新哪些设置才能通过 Gmail 发送?请注意,Postfix 的配置端口与上面的 25 不同。

再次重申,Alpine 电子邮件客户端可以顺利通过 Gmail 发送,因此问题不在于密码本身,而在于密码在文件中的存储方式。在 Alpine 配置文件中,它是一个用空格分隔的字母数字序列。

例子是:

[smtp.gmail.com]:587 [电子邮件保护]:多迪尔

而应用程序密码更像是“xxx yyy zzz”,这在 Pine 中很有效。另请参阅:

https://askubuntu.com/a/1201334/847449

答案1

关键步骤:

 # chmod 600 /etc/postfix/sasl_passwd
 # postmap /etc/postfix/sasl_passwd
 # postmap /etc/postfix/tls_policy

https://access.redhat.com/solutions/3201002

似乎有效。我所做的唯一更改是使用 ../postfix/sasl/sasl_passwd 而不是上面的路径。只是因为该目录随 postfix 一起提供。至少就我所记得的而言。

也可以看看:

https://wpaq.com/configure-postfix-smtp-relay/

相关内容