【问题标题】:Sendmail does not send emails from GCE VM instanceSendmail 不从 GCE VM 实例发送电子邮件
【发布时间】:2016-12-31 09:06:44
【问题描述】:

我在我的 Google Cloud Compute Engine 上安装了一个 WordPress 网站,但我无法发送邮件。于是在网上搜索后发现Sendmail

安装并配置了最新版本:

$ sudo apt-get update
$ sudo apt-get install sendmail

运行 sendemail 配置,对所有内容都回答“是”:

$ sudo sendmailconfig

编辑了127.0.0.1 localhost instance-1 行(instance-1 是我的 Google 云实例):

$ sudo vim /etc/hosts # changed 

重启 Apache:

sudo service apache2 restart

当我在终端中运行以下命令时,没有任何反应,并且我无法再运行命令。所以看起来这个过程还没有结束。

$ sendmail example@email.com

$ date | sendmail -v example@email.com 的输出返回:

example@email.com... Connecting to [127.0.0.1] via relay...
220 instance-1.c.myproject.internal ESMTP Sendmail 8.14.4/8.14.4/Debian-8; Wed, 24 Aug 2016 09:42:18 GMT; (No UCE/UBE) logging access from: localhost(OK)-localhost [127.0.0.1]
>>> EHLO instance-1.c.myproject.internal
250-instance-1.c.myproject.internal Hello localhost [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-EXPN
250-VERB
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-DELIVERBY
250 HELP
>>> VERB
250 2.0.0 Verbose mode
>>> MAIL From:<info@instance-1.c.myproject.internal> SIZE=29
250 2.1.0 <info@instance-1.c.myproject.internal>... Sender ok
>>> RCPT To:<example@email.com>
>>> DATA
250 2.1.5 <example@email.com>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .

我的日志文件/var/log/mail.log 显示了很多这样的行:

Aug 25 07:56:02 instance-1 sm-mta[19958]: u7OCN1Wu013988: to=<example@email.com>, delay=19:33:01, xdelay=00:10:36, mailer=esmtp, pri=5340422, relay=alt4.gmail-smtp-in.l.google.com. [173.194.72.27], dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
Aug 25 07:56:02 instance-1 sm-mta[19958]: u7OC9iDu013870: to=<example@email.com>, delay=19:46:18, xdelay=00:00:00, mailer=esmtp, pri=10560423, relay=alt4.gmail-smtp-in.l.google.com., dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
Aug 25 07:56:02 instance-1 sm-mta[19958]: u7OBliSC013710: to=<example@email.com>, delay=20:08:18, xdelay=00:00:00, mailer=esmtp, pri=10740386, relay=alt4.gmail-smtp-in.l.google.com., dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
Aug 25 07:56:02 instance-1 sm-mta[19958]: u7O94ubM013110: to=<example@email.com>, delay=22:51:06, xdelay=00:00:00, mailer=esmtp, pri=11460376, relay=alt4.gmail-smtp-in.l.google.com., dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.

【问题讨论】:

  • 你检查过 sendmail 的日志文件吗?
  • @AndrzejA.Filip 在我的问题中检查我的 mail.log 文件的输出。
  • 查看您的日志文件我会说您运行 sendmail 的主机无法连接到 Internet。您可以通过从终端运行以下命令来检查这一点:nc alt4.gmail-smtp-in.l.google.com 25
  • @PeterSkarpetis 我按照你说的那样运行了命令,但是我什么也没得到,我也不能再输入命令了。这是什么意思?
  • 您无法从 Google Compute Engine 发送邮件,Google 会在 25 日阻止所有传出流量。您必须使用像 Sendgrid 这样的第三方来发送邮件。 cloud.google.com/compute/docs/tutorials/sending-mail

标签: apache google-cloud-platform debian google-compute-engine sendmail


【解决方案1】:

无法直接从您的 GCE 虚拟机发送电子邮件。

请查看文档Always blocked traffic

  • 到 TCP 目标端口 25 (SMTP) 的出口流量

也可以在Using standard email ports:

由于存在滥用风险,当目标位于您的 VPC 网络之外时,到目标 TCP 端口 25 的连接始终会被阻止。这包括在 Google Workspace 中使用 SMTP 中继。

根据维基百科文章Simple Mail Transfer Protocol

自 SMTP 于 1981 年推出以来,它已被更新、修改和 多次延长。今天常用的协议版本有 具有各种身份验证扩展的可扩展结构, 加密、二进制数据传输、国际化电子邮件地址。 SMTP 服务器通常在端口上使用传输控制协议 25号。

这是在 1982 年与 RFC 821, Appendix A 首次决定的,从那时起一直如此。在RFC5321你可以看到:

4.5.4.2。接收策略

SMTP 服务器应该尝试在 SMTP 上保持挂起的侦听 端口(由 IANA 指定为端口 25)。

这是什么意思?您不能简单地更改端口,因为其他 SMTP 服务器没有机制知道您正在使用非标准端口,并且您不能使用任何其他端口发送到其他服务器。

有没有办法从 GCE 虚拟机发送电子邮件?

是的,让我们回到文档Using standard email ports

Google Cloud 对使用目标 TCP 端口 587 或 465 发送到外部目标 IP 地址的流量没有任何限制。

端口 587 和 465 可用于 SMTP 邮件提交 (RFC6409)。这意味着您可以使用外部邮件中继(您自己的或第 3 方)进行身份验证的 SMTP,并且此服务器在端口 25 上处理向其他邮件系统的传递。例如,您可以使用这些第 3 方服务:SendGrid、@987654329 @,或Mailjet。此外,您可以通过Google Workspace 转发您的邮件,或者只使用Google Workspace

【讨论】:

    【解决方案2】:

    是的,可以从实例发送电子邮件,tutorial 中解释了所有内容。

    默认情况下,Compute Engine 允许除端口 25 之外的所有端口上的出站连接,由于存在滥用风险,该端口已被阻止。所有其他端口都是开放的,包括端口 587 和 465。

    【讨论】:

      【解决方案3】:

      您无法从 Google Compute Engine 发送邮件,Google 会在 25 日阻止所有传出流量。

      您将不得不使用像 Sendgrid to send mail 这样的第三方。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-04
        • 2014-08-03
        • 2011-03-03
        • 2016-03-02
        • 2017-01-20
        • 2018-07-22
        相关资源
        最近更新 更多