邮件服务器不在 Web 主机上时的 sendmail 和 MX 记录
我确信这是一个很容易解决的问题,但我一整天都在绞尽脑汁。
我正在为客户开发一个新网站。 该网站位于(这是一个示例)website.com。 我有一个 PHP 表单脚本,用于将访问者的请求通过电子邮件发送至 [email protected] 。
当我在不同域的临时服务器上编码时,一切正常。 当我将其移至 website.com 时,邮件从未到达。 Web 服务器位于主要 ISP 的虚拟主机上。
以下是我从那时起了解到的情况:我客户的邮件服务器是 Microsoft Exchange,位于其办公室的物理盒子上。 每当外界有人发送电子邮件[email protected]时,邮件就会到达。 但是如果网络服务器发送到同一个电子邮件地址,则每次都会失败。 这不是 PHP 问题。 我将 shell 安全地连接到 Web 服务器,并使用 sendmail 和 UNIX 邮件应用程序对此进行了测试。 我还通过从 shell 向各种电子邮件帐户发送电子邮件来测试它。 例如,我可以给自己发送电子邮件,但 website.com 域中的任何人都可以。
简而言之,当我登录 website.com 时,发送邮件至 [email protected] 、[电子邮件受保护]、[电子邮件受保护] 全部失败。 所有其他地址都工作正常。 我发现那些丢弃的电子邮件被路由到网络服务器的“catchall”帐户,它们位于其收件箱中。
我在 website.com 上进行了 MX 查找。 MX 记录指向 mailsec.website.com。 我可以远程登录到 mailsec.website.com 端口 25 并查看 SMTP 服务器。
在我看来,website.com 在将邮件发送到 [ 时并没有进行 MX 查找电子邮件受保护]。 我的理论是,它会将域识别为本地域,发现没有“请求”用户帐户将其传递到,并将邮件放入包罗万象的帐户中。 我想要的是强制 sendmail 进行 MX 查找并将邮件发送到 Exchange 服务器。 我在这里无计可施了。 我不知道该怎么做。
就此而言,我可能在这里大错特错,并且完全误诊了这一点。 互联网邮件和 MX 对我来说一直像是一种魔法,我的无知在这个问题上显而易见。
This is a problem I'm sure is easy to fix, but I've been banging my head on it all day.
I'm developing a new web site for a client. The web site resides at (this is an example) website.com. I have a PHP form script to email visitors' requests to [email protected].
When I coded this on a staging server on a different domain, all worked fine. When I moved it to website.com, the mail messages never arrived. The web server is on a virtual host with a major ISP.
Here's what I've learned since then: My client's mail server is Microsoft Exchange on a box physically in their office. Whenever someone on the outside world emails [email protected], the mail arrives. But if the web server sends to the same email address, it fails every time. This is not a PHP problem. I secure shell in to the web server and have tested this both with sendmail and the UNIX mail application. I've also tested it by emailing various email accounts from the shell. I can email myself, for example, just nobody at the website.com domain.
In short, when I'm logged in to website.com, mail to [email protected], [email protected], [email protected] all fail. All other addresses work fine. What I've discovered is those dropped emails are routed to the web server's "catchall" account where they sit in its inbox.
I've done an MX lookup on website.com. The MX record points to mailsec.website.com. I can telnet to mailsec.website.com port 25 and see the SMTP server.
It appears to me that website.com isn't doing an MX lookup when it's sending mail to [email protected]. My theory is that it recognizes the domain as local, sees that there's no "requests" user account to deliver it to, and drops the mail into the catchall account. What I want is to force sendmail to do the MX lookup and send the message on to the Exchange server. I'm at wit's end here. I can't figure out how to do this.
For that matter, I may be way off base here and have misdiagnosed this entirely. Internet mail and MX has always seemed a black art to me, and my ignorance is certainly showing in this question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我认为问题在于 sendmail (您的进程)正在与本地 sendmail 守护进程通信。 本地sendmail守护进程认为因为它是website.com,所以它应该知道如何传递电子邮件。 不幸的是,to 字段中的实际地址并不存在于 Web 服务器上,因此它将其转储到“catchall”邮箱中。 您应该与您的 ISP 联系并让他们更新其 sendmail 配置,以便将邮件发送至 [email] protected] 转发到邮件交换器而不是在本地处理。
I think the problem is that sendmail (your process) is talking to the local sendmail daemon. The local sendmail daemon thinks that because it is website.com, it should know how to deliver the email. Unfortunately, the actual address in the to field does not exist on the web server and thus it dumps it in the "catchall" mail box. You should talk to your ISP and have them update their sendmail configuration so that mail addressed to [email protected] gets forward to the mail exchanger instead of being handled locally.
Sendmail 默认猜测本地电子邮件域列表。
可以使用 sendmail.mc 文件中的以下行将其关闭:
以 root 身份列出更改前后的本地电子邮件域:
您将看到哪些域应“手动”添加到(通常)/etc/mail/local禁用自动猜测后的 -host-names 文件。
更改
sendmail.mc
后:sendmail.cf
文件Sendmail by default guesses list of local email domains.
It can be turned off using the following line in your sendmail.mc file:
As root list local email domains before and after the change using:
You will see which domains should be added "manually" to (usually) /etc/mail/local-host-names file after disabling auto-guessing.
After changing
sendmail.mc
:sendmail.cf
filetvanfosson 基本上有它,但作为临时解决方法,您应该能够更改脚本,以便它邮寄 '[电子邮件受保护]',然后邮件将被传递到实际的邮件服务器。
tvanfosson basically has it, but as a temporary workaround, you should be able to change your script so that it mails '[email protected]', and then the mail will get delivered to the actual mail server.
编辑 tsm.cf 文件(在 /etc/mail/ 或类似文件中)以包含
在 DOMAIN() 和 MAILER() 行之间。 由于您正在编辑该文件,因此您可能还希望通过
更改 tsm.cf 文件(或任何 sendmail 配置文件)后,重新启动或 SIGHUP sendmail 进程来提高安全性。
此更改是必要的,因为域的 WWW 和 MX 服务器不存在于同一进程空间中; 此功能触发 sendmail 使用其外部传递机制来处理域的邮件。
tsm.cf 文件的编辑部分应类似于以下内容:
Edit the tsm.cf file (in /etc/mail/ or similar) to include
between the DOMAIN() and MAILER() lines. Since you're editing the file, you may want to also improve security with
After changing the tsm.cf file (or any sendmail config file), restart or SIGHUP the sendmail process.
This change is necessary because the WWW and MX servers for the domain do not exist in the same process space; this FEATURE triggers sendmail to process messages for the domain using it's external delivery mechanism.
The edited portion of the tsm.cf file should look similar to this:
对我有用的是在托管网站的网络服务器上添加 MX 记录,该记录指向原始域名服务器上分配的主机。 在此处介绍的情况下,mx 记录将指向:mailsec.website.com
What worked for me was to add an MX record on the webserver hosting the website, that points to the host assigned on the original domain name server. In the case presented here would be an mx record pointing to: mailsec.website.com
我是新来的。 想扩展RB_CWI答案,但我无权发表评论。
他的解决方案效果很好。
您不需要定义 DOMAIN()。
但是,在我的系统上,我需要安装 sendmail-cf 软件包。
下面的说明是在 CentOS 6.5 上完成的
首先,安装 sendmail-cf
然后,编辑 senmail.mc
在文件底部添加 FEATURE(relay_entire_domain)dnl,所以它看起来像:
保存文件,并重新启动sendmail。
I'm new here. Wanted to extend RB_CWI answer, but I am not allowed to comment.
His solution worked great.
You are not required to define the DOMAIN().
However, on my system I was required to install the sendmail-cf package.
The instructions below were done on CentOS 6.5
First, install sendmail-cf
Then, edit the senmail.mc
At the bottom of the file add FEATURE(relay_entire_domain)dnl, so it looks like:
Save the file, and restart sendmail.
陷入同样的问题。 MX 指向外部 Exchange 服务器,但 php/sendmail 没有查找此记录。 相反,WordPress 在该网络服务器上发布的邮件会被放入综合邮箱中。
解决方案是删除网络服务器上的所有邮箱。 现在,sendmail 对 MX 感兴趣,所有邮件都发送到 Exchange。
但是,Exchange 使用网络空间的邮件服务器作为智能主机来发送邮件。 作为解决方案,我们能够使用 FTP 凭据来访问邮件服务器。 我认为这个解决方案并不适用于这个星球上的每个提供商,但在我们的案例 (all-inkl.com) 中它成功了。
Got stuck on the same problem. MX points to an external Exchange server but php/sendmail did not lookup this record. Instead mails posted by WordPress on this webserver dropped in the catchall-mailbox.
Solution was to delete ALL mailboxes on the webserver. Now sendmail was interested in the MX and all mails went to the Exchange.
However, the Exchange uses the webspace's mail server as SmartHost for outgoing mails. As solution for this, we were able to use the FTP credentials for accessing the mail server. I assume this solution does not work on every provider on this planet, but in our case (all-inkl.com) it worked out.