【问题标题】:How to use sendmail with SendGrid from Google Compute Engine?如何通过 Google Compute Engine 的 SendGrid 使用 sendmail?
【发布时间】:2015-01-21 16:36:15
【问题描述】:

我有一个使用 Joomla! 运行的简单网站,它有一个联系表格,访问者可以通过该表格向我发送消息。此消息使用sendmail 服务通过电子邮件发送。

网站机器在 Google Compute Engine 中运行,默认情况下我无法从它发送电子邮件(这是 Google 施加的限制)。要实现发送电子邮件的目的,需要第三方服务,例如 SendGrid。

我使用Google Cloud partner program 在 SendGrid 上创建了一个免费帐户,验证了我的用户等等。该帐户已正确配置。

根据this tutorial,我将我的sendmail 服务配置为使用SendGrid 来传递电子邮件。一切似乎都很好,但是……根本没有传递任何消息。

我在/var/log/mail.log 的邮件日志显示:

Jan 21 16:22:10 web-hosting sm-mta[16350]: t0JHWaec027559: to=<my@email.com>, delay=1+22:49:34, xdelay=00:00:00, mailer=relay, pri=23251559, re
lay=smtp.sendgrid.net., dsn=4.0.0, stat=Deferred: Connection timed out with smtp.sendgrid.net.

According to Google,我的机器无法使用端口25465587,所以我在sendmail.mc文件中将配置改为使用端口2525。没有任何改变。

有什么提示吗?我的机器运行的是 Ubuntu 14.04LTS。

【问题讨论】:

  • 您是否仔细检查过您的帐户是否正在发送电子邮件?您可以通过 curl 进行测试:$ curl -d 'to=destination@example.com&amp;amp;toname=Destination&amp;amp;subject=Example Subject&amp;amp;text=testingtextbody&amp;amp;from=info@domain.com&amp;amp;api_user=your_sendgrid_username&amp;amp;api_key=your_sendgrid_password' https://api.sendgrid.com/api/mail.send.json
  • @heitortsergent 是的,直接使用 API 可以完美发送邮件。

标签: email sendmail google-compute-engine sendgrid


【解决方案1】:

好的,我找到了问题。

我原来的/etc/mail/sendmail.mc 文件没有#dnl define(‘SMART_HOST’, ‘smtp.your.provider’)dnl 行,所以我不知道将配置放在哪里(source):

define(`SMART_HOST', `smtp.sendgrid.net')dnl
FEATURE(`access_db')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 2525')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 2525')dnl

(注意:对于 Google Compute Engine 机器,您需要使用 2525 端口而不是默认的 587)

问题是,你不能把它放在文件的末尾。当我将它放在“请勿触摸此处”部分之后时,配置开始工作:

dnl # Items controlled by /etc/mail/sendmail.conf - DO NOT TOUCH HERE
...
DAEMON_OPTIONS(`Family=inet,  Name=MSP-v4, Port=submission, M=Ea, Addr=127.0.0.1')dnl
dnl # SendGrid code here

【讨论】:

    猜你喜欢
    • 2015-07-20
    • 2014-06-21
    • 2013-10-09
    • 2015-10-16
    • 2015-02-19
    • 1970-01-01
    • 2019-03-14
    • 2017-06-29
    • 1970-01-01
    相关资源
    最近更新 更多