但不幸的是,无论我使用的是:
我的后缀配置文件是:
# 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_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = mainserver.mskillsa.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, mskillsa.com, mainserver.mskillsa.com, localhost.mskillsa.com, localhost
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
smtp_sasl_auth_enable = yes我的域名是: mskillsa.com
我的房号是: mainserver.mskillsa.com
我的电子邮件是: info@mskillsa.com
一些记录检查程序告诉我,我没有DKIM记录,我尝试使用第三方DKIM记录生成器,我使用它,但仍然有相同的问题与DKIM记录!
我的PHPMailer代码:
isSMTP();
// Define SMTP host
$mail->Host = "mail.mskillsa.com";
// enable SMTP authentication
$mail->SMTPAuth = "true";
// Set type of encryption (ssl/tls)
$mail->SMTPSecure = "ssl";
// Set port to connect SMTP
$mail->Port = "465";
// Set username
$mail->Username = "example@mskillsa.com";
// Set password
$mail->Password = "password";
// Set email Subject
$mail->Subject = "Hello Info Testing";
// Set sender email
$mail->setFrom("example@mskillsa.com");
// Email Body
$mail->Body = "Hello testing...";
// Add recipient
$mail->addAddress('recipient_example@gmail.com');
// Finally Send Email
if ($mail->send()) {
echo "Sent";
} else {
echo "Not Sent";
}
// Closing SMTP Connection
$mail->smtpClose();我得到了以下错误:
2022-08-08 15:42:54 CLIENT -> SERVER: EHLO mskillsa.com
2022-08-08 15:42:54 CLIENT -> SERVER: STARTTLS
SMTP Error: Could not connect to SMTP host. Connection failed. stream_socket_enable_crypto(): Peer certificate CN=`localhost.localdomain' did not match expected CN=`mainserver.mskillsa.com'
2022-08-08 15:42:54 CLIENT -> SERVER: QUIT
2022-08-08 15:42:54
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Not Sent我的master.cf文件:
#
# Postfix master process configuration file. For details on the format
# of the file, see the master(5) manual page (command: "man 5 master" or
# on-line: http://www.postfix.org/master.5.html).
#
# Do not forget to execute "postfix reload" after editing this file.
#
# ==========================================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (no) (never) (100)
# ==========================================================================
smtp inet n - y - - smtpd
#smtp inet n - y - 1 postscreen
#smtpd pass - - y - - smtpd
#dnsblog unix - - y - 0 dnsblog
#tlsproxy unix - - y - 0 tlsproxy
#submission inet n - y - - smtpd
# -o syslog_name=postfix/submission
# -o smtpd_tls_security_level=encrypt
# -o smtpd_sasl_auth_enable=yes
# -o smtpd_tls_auth_only=yes
# -o smtpd_reject_unlisted_recipient=no
# -o smtpd_client_restrictions=$mua_client_restrictions
# -o smtpd_helo_restrictions=$mua_helo_restrictions
# -o smtpd_sender_restrictions=$mua_sender_restrictions
# -o smtpd_recipient_restrictions=
# -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
#smtps inet n - y - - smtpd
# -o syslog_name=postfix/smtps
# -o smtpd_tls_wrappermode=yes
# -o smtpd_sasl_auth_enable=yes
# -o smtpd_reject_unlisted_recipient=no
# -o smtpd_client_restrictions=$mua_client_restrictions
# -o smtpd_helo_restrictions=$mua_helo_restrictions
# -o smtpd_sender_restrictions=$mua_sender_restrictions
# -o smtpd_recipient_restrictions=
# -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
#628 inet n - y - - qmqpd
pickup unix n - y 60 1 pickup
cleanup unix n - y - 0 cleanup
qmgr unix n - n 300 1 qmgr
#qmgr unix n - n 300 1 oqmgr
tlsmgr unix - - y 1000? 1 tlsmgr
rewrite unix - - y - - trivial-rewrite
bounce unix - - y - 0 bounce
defer unix - - y - 0 bounce
trace unix - - y - 0 bounce
verify unix - - y - 1 verify
flush unix n - y 1000? 0 flush
proxymap unix - - n - - proxymap
proxywrite unix - - n - 1 proxymap
smtp unix - - y - - smtp
relay unix - - y - - smtp
-o syslog_name=postfix/$service_name
# -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
showq unix n - y - - showq
error unix - - y - - error
retry unix - - y - - error
discard unix - - y - - discard
local unix - n n - - local
virtual unix - n n - - virtual
lmtp unix - - y - - lmtp
anvil unix - - y - 1 anvil
scache unix - - y - 1 scache
#
# ====================================================================
# Interfaces to non-Postfix software. Be sure to examine the manual
# pages of the non-Postfix software to find out what options it wants.
#
# Many of the following services use the Postfix pipe(8) delivery
# agent. See the pipe(8) man page for information about ${recipient}
# and other message envelope options.
# ====================================================================
#
# maildrop. See the Postfix MAILDROP_README file for details.
# Also specify in main.cf: maildrop_destination_recipient_limit=1
#
maildrop unix - n n - - pipe
flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
#
# ====================================================================
#
# Recent Cyrus versions can use the existing "lmtp" master.cf entry.
#
# Specify in cyrus.conf:
# lmtp cmd="lmtpd -a" listen="localhost:lmtp" proto=tcp4
#
# Specify in main.cf one or more of the following:
# mailbox_transport = lmtp:inet:localhost
# virtual_transport = lmtp:inet:localhost
#
# ====================================================================
#
# Cyrus 2.1.5 (Amos Gouaux)
# Also specify in main.cf: cyrus_destination_recipient_limit=1
#
#cyrus unix - n n - - pipe
# user=cyrus argv=/cyrus/bin/deliver -e -r ${sender} -m ${extension} ${user}
#
# ====================================================================
# Old example of delivery via Cyrus.
#
#old-cyrus unix - n n - - pipe
# flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user}
#
# ====================================================================
#
# See the Postfix UUCP_README file for configuration details.
#
uucp unix - n n - - pipe
flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
#
# Other external delivery methods.
#
ifmail unix - n n - - pipe
flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp unix - n n - - pipe
flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
scalemail-backend unix - n n - 2 pipe
flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
mailman unix - n n - - pipe
flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
${nexthop} ${user}发布于 2022-08-08 16:20:30
在使用PHPmailer时,您会使事情过于复杂。
由于SMTP服务器位于本地主机上,您可以做的最简单的事情就是使用 not,而不为$mail->Host、$mail->SMTPAuth、$mail->SMTPSecure、$mail->Port、$mail->Username和$mail->Password设置任何值。还省略了$mail->smtpClose()。所以你只剩下
$mail = new PHPMailer();
$mail->Subject = "Hello Info Testing";
$mail->setFrom("example@mskillsa.com");
$mail->Body = "Hello testing...";
$mail->addAddress('recipient_example@gmail.com');
if ($mail->send()) {
echo "Sent";
} else {
echo "Not Sent";
}就像本教程的第一个例子(“如何用PHPmailer发送第一封电子邮件”)。
使用这种方法,PHPmailer将使用与PHP内部mail()函数完全相同的发送邮件方法,即使用sendmail直接将邮件提交给本地邮件服务器。在我看来,这是在同时运行本地SMTP服务器的计算机上发送邮件的最恰当方法。如果这个方法以前确实适用于您(命令行中的mail和mail()函数),那么它也应该在这里工作。
但是,如果您坚持使用SMTP,有几个选项可以这样做,但每个选项都需要对参数进行一些修改。
首先,尝试使用到本地服务器($mail->SMTPSecure = "ssl")的安全连接。如果连接到本地主机,这绝对不会给安全带来任何好处,这是造成问题的主要原因,因为您发布的错误对话框显示PHPmailer在证书验证方面失败。所以首先试着完全摆脱加密。替换
$mail->Host = "mail.mskillsa.com";通过
$mail->Host = "localhost";或
$mail->Host = "127.0.0.1";并删除行$mail->SMTPSecure = "ssl"。您还可能需要添加以下内容:
$mail->SMTPAutoTLS = false;阻止PHPmailer自动使用加密,如果它看到服务器支持它。
因为您的后缀服务器信任localhost (这是绝对正确的)-- mynetworks=中包含了localhost地址。因此,您可以简单地连接到标准SMTP端口25。您还应该消除身份验证,因为您当前的后缀配置至少在25端口上支持身份验证(您没有在端口25上发布您的master.cf,其中可能定义了端口465上的提交服务配置,因此我不确定那里是否支持身份验证,但是从您发布的对话框(编辑之前的上一个版本)中,我看到服务器没有发布AUTH广告)。因此,删除$mail->SMTPAuth、$mail->Username和$mail->Password行,并设置
$mail->Port = 25;因此,下一个可行的选项应该是:
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = "localhost";
$mail->SMTPAutoTLS = false;
$mail->Port = 25;
$mail->Subject = "Hello Info Testing";
$mail->setFrom("example@mskillsa.com");
$mail->Body = "Hello testing...";
$mail->addAddress('recipient_example@gmail.com');
if ($mail->send()) {
echo "Sent";
} else {
echo "Not Sent";
}
$mail->smtpClose();最后,如果您真的想使用加密的身份验证提交(尽管我想再次强调,它在连接到本地SMTP服务器时没有意义),您也需要修复后缀配置。
正如我所说的,后缀配置不启用身份验证。您可能希望使用行smtp_sasl_auth_enable = yes来打开它,但这会打开将后缀<#>connecting作为客户端发送邮件给它的的身份验证,而不是对Postfix中的SMTP服务器进行身份验证。你通常不想要这个。如果没有附带的参数smtp_sasl_password_maps,定义后缀应该用来对远程服务器进行身份验证的凭据,则该参数根本不起作用。因此,从您的main.cf中删除这一行。
在后缀服务器中启用身份验证的参数是smtpd_sasl_auth_enable = yes (请注意名称中的"d“),但you不应该将其放在 main.cf中,因为在配置邮件服务器以启用端口25上的身份验证方面,这不是一个好做法。相反,您应该只在端口465上的提交服务中启用身份验证,该端口是在master.cf中定义的。你还没发你的master.cf,所以我不能告诉你怎么改正它。
假设您已经修复了您的master.cf,那么PHPmailer参数中仍然需要修复一些东西。PHPmailer在证书验证中失败,因为您的服务器上有一个自签名证书,而PHPmailer by默认值需要证书颁发机构的“正式”证书并尝试验证它。因此,除了PHPmailer代码中已经包含的内容之外,还需要添加以下内容:
/* Disable some SSL checks. */
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);我从我已经链接的教程中获得了这一点,请参阅“如何使用自定义SMTP服务器”下的第二个示例。这是第三种适合你的变体。
更新:现在发布了您的master.cf内容,我发现您根本没有启用提交服务。因此,我想知道最初连接到端口465 (如您的PHPmailer代码中指定的)是如何为您工作的。您有其他软件运行在465端口上吗?因为根据您的master.cf,后缀只监听端口25。
无论如何,要使身份验证提交工作,您需要取消注释您的master.cf中的下列行并重新启动后缀:
#smtps inet n - y - - smtpd
# -o syslog_name=postfix/smtps
# -o smtpd_tls_wrappermode=yes
# -o smtpd_sasl_auth_enable=yes
# -o smtpd_reject_unlisted_recipient=no
# -o smtpd_client_restrictions=$mua_client_restrictions
# -o smtpd_helo_restrictions=$mua_helo_restrictions
# -o smtpd_sender_restrictions=$mua_sender_restrictions
# -o smtpd_recipient_restrictions=
# -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING但是,您还需要一些将检查用户凭据的身份验证器。这是后缀之外的一些程序,例如Dovecot。您需要在两个地方配置身份验证。首先,您需要在后缀main.cf文件中添加以下内容:
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth然后,您需要在Dovecot中为Postfix配置一个身份验证服务。有一个Dovecot网站教程如何做到这一点。
https://serverfault.com/questions/1107569
复制相似问题