首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用WordPress设置后缀和Google套件电子邮件

用WordPress设置后缀和Google套件电子邮件
EN

Server Fault用户
提问于 2020-10-07 11:56:59
回答 1查看 801关注 0票数 1

我终于得到了WordPress的设置,并使用WP在VPS上工作。直到我想改变我在Settings > General下找到的D1并提交来自ContactForm7的表格,我才意识到我在输入的电子邮件地址上没有收到任何电子邮件。

我有一个公共领域,我购买了Namescheap,我有一封电子邮件与谷歌G套件(现在谷歌工作区)。在这篇文章中,我将把我的公共领域称为example.com。我的Linux服务器有ubuntu-server.example.com的FQDN,我的电子邮件是info@example.com,它有一个别名email;webmaster@example.com

我已经安装了Apache2.4,并且选择了使用PHP版本而不是mod_php,因为它更快,但却消耗了更多的内存。PHP和Apache在Linux用户和组www-data下运行。

我想安装后缀,所以在遵循各种指南之后,我在Google套件中安装了Gmail上的“较不安全的应用程序”,因为我启用了2FA。

我的未修改的PHP.ini文件与sendmail_path注释

/etc/php/7.4/fpm/php.ini

代码语言:javascript
运行
复制
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me@example.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path =

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail().
;mail.force_extra_parameters =

; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = Off

; The path to a log file that will log all mail() calls. Log entries include
; the full path of the script, line number, To address and headers.
;mail.log =
; Log mail to syslog (Event Log on Windows).
;mail.log = syslog

我的配置有问题,我一直在使用/var/log/mail.log的日志来诊断问题。我找到了一篇非常有用的文章这里,展示了如何记录电子邮件头。

/etc/后缀/头检查

代码语言:javascript
运行
复制
/^subject:/      WARN
/^to:/           WARN
/^from:/         WARN
/^Subject:/      WARN
/^To:/           WARN
/^From:/         WARN

/etc/后缀/main.cf

代码语言:javascript
运行
复制
# 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

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

# TLS parameters
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

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = encrypt
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_tls_CApath=/etc/ssl/certs
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = ubuntu-server.example.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, example.com, ubuntu-server.example.com, localhost.example.com, localhost
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 = all
inet_protocols = all

header_checks = regexp:/etc/postfix/header_checks

/etc/后缀/sasl/sasl_passwd

代码语言:javascript
运行
复制
[smtp-relay.gmail.com]:587 webmaster@example.com:password

只需在Administration Email Address的仪表板中更改WordPress,就会产生以下日志:

/var/log/mail.log (更改管理电子邮件地址)

代码语言:javascript
运行
复制
Oct 14 20:34:50 ubuntu-server postfix/pickup[122612]: 615314047B: uid=33 from=
Oct 14 20:34:50 ubuntu-server postfix/cleanup[122616]: 615314047B: warning: header To: personal-email@yahoo.co.uk from local; from=
Oct 14 20:34:50 ubuntu-server postfix/cleanup[122616]: 615314047B: warning: header Subject: [The Surge Network] New Admin Email Address from local; from=
Oct 14 20:34:50 ubuntu-server postfix/cleanup[122616]: 615314047B: warning: header From: WordPress  from local; from=
Oct 14 20:34:50 ubuntu-server postfix/cleanup[122616]: 615314047B: message-id=
Oct 14 20:34:50 ubuntu-server postfix/qmgr[122614]: 615314047B: from=, size=1000, nrcpt=1 (queue active)
Oct 14 20:34:50 ubuntu-server postfix/smtp[122618]: 615314047B: SASL authentication failed; server smtp-relay.gmail.com[74.125.133.28] said: 535-5.7.8 Username and Password not accepted. Learn more at?535 5.7.8  https://support.google.com/mail/?p=BadCredentials i127sm10296wmi.19 - gsmtp
Oct 14 20:34:50 ubuntu-server postfix/smtp[122618]: connect to smtp-relay.gmail.com[2a00:1450:400c:c08::1c]:587: Network is unreachable
Oct 14 20:34:50 ubuntu-server postfix/smtp[122618]: 615314047B: to=, relay=none, delay=0.09, delays=0.01/0/0.08/0, dsn=4.4.1, status=deferred (connect to smtp-relay.gmail.com[2a00:1450:400c:c08::1c]:587: Network is unreachable)

正如我前面提到的,Apache和PHP在www-data Linux用户和组(它们的默认用户和组)下运行,它们显着地显示了日志。有趣的是,如果我通过ContactForm7 www-data提交一份表单,它似乎又被否决了。

/var/log/mail.log (提交CF7表单)

代码语言:javascript
运行
复制
Oct 14 21:09:04 ubuntu-server postfix/pickup[122612]: C31844047F: uid=33 from=
Oct 14 21:09:04 ubuntu-server postfix/cleanup[123010]: C31844047F: warning: header To: personal-email@yahoo.co.uk from local; from=
Oct 14 21:09:04 ubuntu-server postfix/cleanup[123010]: C31844047F: warning: header Subject: =?us-ascii?Q?John_Smith_has_sumbitted_a_form_at_WordPress_Si?=  =?us-ascii?Q?te?= from local; from=
Oct 14 21:09:04 ubuntu-server postfix/cleanup[123010]: C31844047F: warning: header From: Webmaster  from local; from=
Oct 14 21:09:04 ubuntu-server postfix/cleanup[123010]: C31844047F: message-id=
Oct 14 21:09:04 ubuntu-server postfix/qmgr[122614]: C31844047F: from=, size=693, nrcpt=1 (queue active)
Oct 14 21:09:04 ubuntu-server postfix/smtp[123012]: C31844047F: SASL authentication failed; server smtp-relay.gmail.com[74.125.140.28] said: 535-5.7.8 Username and Password not accepted. Learn more at?535 5.7.8  https://support.google.com/mail/?p=BadCredentials b14sm13955wrm.42 - gsmtp
Oct 14 21:09:04 ubuntu-server postfix/smtp[123012]: connect to smtp-relay.gmail.com[2a00:1450:400c:c08::1c]:587: Network is unreachable
Oct 14 21:09:04 ubuntu-server postfix/smtp[123012]: C31844047F: to=, relay=none, delay=0.14, delays=0.03/0.03/0.08/0, dsn=4.4.1, status=deferred (connect to smtp-relay.gmail.com[2a00:1450:400c:c08::1c]:587: Network is unreachable)
EN

回答 1

Server Fault用户

发布于 2020-10-07 16:08:51

不要将系统主机名设置为裸域名。不要将后缀的邮件名设置为裸域名。不要将裸域名添加到Postfix的mydestination或任何其他Postfix配置选项中。如果这样做,将导致Postfix试图在本地发送邮件,而不是将邮件发送到Internet。

用域名的子域命名系统。将完全限定的域名(包括子域)指定为后缀邮件名。例如,您可以调用您的系统capacitor,而FQDN将是capacitor.example.com。然后,example.com的邮件将被送到它应该去的任何地方。而且只有@ capacitor.example.com的邮件才会在本地发送(当然,除非您将其转发到某个地方)。

票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/1036763

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档