配置 sendmail 以将电子邮件发送到 Outlook 服务器

配置 sendmail 以将电子邮件发送到 Outlook 服务器

目前,我正在使用 Redhat 发行版,我可以使用 sendmail 向 Gmail 服务器发送电子邮件,但是当我尝试使用 Outlook 服务器时,它会在 maillog 文件中生成下面的日志。(outlook_sender@mydomain 发送到 outlook_receiver@mydomain)

Sep  7 11:23:49 localhost sendmail[12785]: starting daemon (8.14.7): SMTP+queueing@01:00:00
Sep  7 11:23:49 localhost sm-msp-queue[12803]: starting daemon (8.14.7): queueing@01:00:00
Sep  7 11:25:14 localhost sendmail[12902]: 0874PE57012902: from=root, size=219, class=0, nrcpts=1, msgid=<[email protected]>, relay=root@localhost
Sep  7 11:25:14 localhost sendmail[12903]: 0874PELI012903: from=<[email protected]>, size=477, class=0, nrcpts=1, msgid=<[email protected]>, proto=ESMTP, daemon=MTA, relay=localhost [127.0.0.1]
Sep  7 11:25:14 localhost sendmail[12902]: 0874PE57012902: to=outlook_receiver@mydomain, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30219, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (0874PELI012903 Message accepted for delivery)
Sep  7 11:25:14 localhost sendmail[12905]: STARTTLS=client, relay=xsp-efz.ms-acdc.office.com., version=TLSv1/SSLv3, verify=FAIL, cipher=ECDHE-RSA-AES256-GCM-SHA384, bits=256/256
Sep  7 11:25:19 localhost sendmail[12905]: 0874PELI012903: to=<outlook_receiver@mydomain>, ctladdr=<[email protected]> (0/0), delay=00:00:05, xdelay=00:00:05, mailer=relay, pri=120477, relay=xsp-efz.ms-acdc.office.com. [40.100.29.34], dsn=5.0.0, stat=Service unavailable
Sep  7 11:25:19 localhost sendmail[12905]: 0874PELI012903: forward /root/.forward.localhost: World writable directory
Sep  7 11:25:19 localhost sendmail[12905]: 0874PELI012903: forward /root/.forward: World writable directory
Sep  7 11:25:19 localhost sendmail[12905]: 0874PELI012903: 0874PJLI012905: DSN: Service unavailable
Sep  7 11:25:19 localhost sendmail[12905]: 0874PJLI012905: to=<[email protected]>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=31712, dsn=2.0.0, stat=Sent

以下是sendmail.mc文件中的配置:

define(`SMART_HOST', `[smtp.office365.com]')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
define(`confAUTH_OPTIONS', `A p')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash -o /etc/mail/auth/outlook_auth.db')dnl
MAILER(`local')dnl
MAILER(`smtp')dnl

以下是 outlook_auth 文件的配置:

AuthInfo:smtp.office365.com "U:root" "I:outlook_sender@mydomain" "P:outlook_password" "M:PLAIN"

当我将 smart_host 从 smtp.office365.com 更改为 smtp.gmail.com 时,将 outlook_auth 文件更改为 gmail_auth 文件(如下所示),将 sendmail.mc 文件映射到 sendmail.cf 文件,然后重新启动 sendmail,它就可以正常工作。

AuthInfo:smtp.gmail.com "U:root" "I:gmail_sender@mydomain" "P:gmail_password" "M:PLAIN"

我不太了解 SMTP 系统的工作原理,昨天只是做了一些研究并配置了 sendmail,所以如果您需要更多信息,请告诉我。

以下是根文件(/var/spool/)的日志:

Reporting-MTA: dns; localhost.localdomain
Received-From-MTA: DNS; localhost
Arrival-Date: Tue, 8 Sep 2020 09:06:09 +0700

Final-Recipient: RFC822; outlook_receiver@mydomain
Action: failed
Status: 5.7.57
Diagnostic-Code: SMTP; 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [SG2PR06CA0235.apcprd06.prod.outlook.com]
Last-Attempt-Date: Tue, 8 Sep 2020 09:06:14 +0700

--08826EuC010437.1599530774/localhost.localdomain
Content-Type: message/rfc822

Return-Path: <[email protected]>
Received: from localhost.localdomain (localhost [127.0.0.1])
    by localhost.localdomain (8.14.7/8.14.7) with ESMTP id 088268uC010433
    for <outlook_receiver@mydomain>; Tue, 8 Sep 2020 09:06:09 +0700
Received: (from root@localhost)
    by localhost.localdomain (8.14.7/8.14.7/Submit) id 088268ti010432
    for outlook_receiver@mydomain; Tue, 8 Sep 2020 09:06:08 +0700
From: root <[email protected]>
Message-Id: <[email protected]>
Date: Tue, 08 Sep 2020 09:06:08 +0700
To: outlook_receiver@mydomain
Subject: test subject
User-Agent: Heirloom mailx 12.5 7/5/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

test content.

--08826EuC010437.1599530774/localhost.localdomain--

答案1

首先,您需要在 Office365 Exchange 管理中心添加合作伙伴连接器。然后在那里添加您的服务器 IP 地址。

现在在您的 SendMail MTA 配置中添加此项

define(`SMART_HOST',`[MX-OF-YOUR-OFFICE365-DOMAIN]')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 25')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 25')dnl
define(`confAUTH_OPTIONS', `A p')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo', `hash -o /etc/mail/authinfo.db')dnl

确保使用您的域 Office365 MX 替换 MX-OF-YOUR-OFFICE365-DOMAIN。

如果您想使用 Office365 Auth Client,请按照以下步骤操作。

使用 Office365 SMTP 用户 ID 通行证更新访问权限

sudo nano /etc/mail/authinfo/office365-auth
AuthInfo: "U:root" "I:[email protected]" "P:YOUR-PASSWORD"

使用 Auth File 生成哈希文件

sudo makemap hash /etc/mail/authinfo.db < /etc/mail/authinfo/office365-auth

重新生成DB文件sudo makemap hash /etc/mail/access.db < /etc/mail/access

这个问题之后

make -C /etc/mail
/etc/init.d/sendmail reload

随后尝试发送邮件。

相关内容