首页 > 解决方案 > Mac Catalina (10.15.4) Postfix -- 无法从命令行发送电子邮件并且 mail.log 不存在

问题描述

Mac Catalina (10.15.4) Postfix -- 无法从命令行发送电子邮件并且 mail.log 不存在

我正在运行 MacOS Catalina (10.15.4) 并尝试从命令行发送电子邮件(这样我以后可以使用 PHP 从网页发送电子邮件),但我的 /var/log/mail.log 丢失了。我尝试使用以下方法手动创建 mail.log:

> sudo touch /var/log/mail.log

但后缀错误消息仍未写入 mail.log。我尝试将 mail.log 所有者更改为 _postifx:

> sudo chown root:admin mail.log

但收到以下错误消息:

> sudo chown _postifx:wheel mail.log 
> chown: _postifx: illegal user name

使用以下命令从命令行发送电子邮件时,电子邮件没有被发送,或者至少没有到达我的邮箱:

date | mail -s "Test Email" [email username]@gmail.com

当我运行mailq时,输出是:

-Queue ID-  --Size-- ----Arrival Time---- -Sender/Recipient-------
93059425861       347 Fri May 22 04:20:10  [machine username]@[machine name].local
(connect to smtp.gmail.com[2607:f8b0:400e:c08::6c]:587: No route to host)
[email username]@gmail.com`

我通常在 VPN 上,但我已经测试过在 VPN 内外都从命令行发送电子邮件,并且在mailq.

我的 sasl_passwd 有一个条目:

[smtp.gmail.com]:587 [电子邮件用户名]@gmail.com:[密码]

我知道 [电子邮件用户名] 和 [密码](在 sasl_passwd 中的“电子邮件用户名”和“密码”周围没有 [])是正确的。

/etc/postfix/main.cf 中唯一关键的(我认为)未注释的行是:

compatibility_level = 2
queue_directory = /private/var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = _postfix
myhostname = smtp.gmail.com
unknown_local_recipient_reject_code = 550
debug_peer_level = 2
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
setgid_group = _postdrop
message_size_limit = 10485760
mailbox_size_limit = 0
biff = no
mynetworks = 127.0.0.0/8, [::1]/128
smtpd_client_restrictions = permit_mynetworks permit_sasl_authenticated permit
recipient_delimiter = +
tls_random_source = dev:/dev/urandom
smtpd_tls_ciphers = medium
inet_interfaces = loopback-only
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_use_tls = yes`
  1. 如何获取写入的错误消息/var/log/mail.log?和
  2. 如何让电子邮件从命令行成功发送(这样我最终可以在网页中通过 PHP 发送电子邮件)?

标签: phpmacosemailpostfix-mta

解决方案


就我而言,大卫杰曼斯的命令帮助了

log stream --predicate '(process == "smtpd") || (process == "smtp") || (process == "master")' --info

有迹象告诉我要包括

smtp_tls_security_level=encrypt
smtp_tls_wrappermode=yes

_

sasl_passwd had to be completely without square brackets

另外我需要编辑 /etc/postfix/generic 文件并添加

@mac16.localhost    serverloginmail@domain.com

紧随其后的是

sudo postmap /etc/postfix/generic

sudo postfix reload

我的 main.cf 文件看起来像这样

mail_owner=_postfix
setgid_group=_postdrop
myhostname=mac16.localhost
compatibility_level=2
relayhost=mail.domain.com:465
#Enable SASL authentication in the Postfix SMTP client.
smtp_sasl_auth_enable=yes
smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options=noanonymous
smtp_sasl_mechanism_filter=plain
#Enable Transport Layer Security (TLS), i.e. SSL.
smtp_use_tls=yes
smtp_tls_security_level=encrypt
smtp_tls_wrappermode=yes
tls_random_source=dev:/dev/urandom
smtp_generic_maps = hash:/etc/postfix/generic

推荐阅读