首页 > 解决方案 > 如何使用凭据在 Rails 6 中实现 Sendgrid

问题描述

我在将 Sendgrid 与 Rails 6 集成时遇到了困难,我现在有点迷茫,因为根据我的终端,电子邮件正在发送到相应的电子邮件地址。

OrderMailer#receipt: processed outbound mail in 17.9ms
Delivered mail 5f0b2c075e025_c1014870205f@aarons-macbook-pro.home.mail (8.1ms)
Date: Sun, 12 Jul 2020 17:28:07 +0200
From: john@anotherpin.com
To: *******@gmail.com
Message-ID: <5f0b2c075e025_c1014870205f@aarons-macbook-pro.home.mail>
Subject: Thank you for ordering from AnotherPin!
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="--==_mimepart_5f0b2c075ceb9_c10148702043a";
 charset=UTF-8
Content-Transfer-Encoding: 7bit


----==_mimepart_5f0b2c075ceb9_c10148702043a
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

Thank you for your order!
-------------------------

Order ID: 148


Name: John Doe


Total price: $18.00


Thanks for your support!


----==_mimepart_5f0b2c075ceb9_c10148702043a
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

但是,当我检查测试电子邮件收件箱时,从未收到邮件,即使检查垃圾邮件文件夹也是如此。

我很困惑,因为我在 Rails 控制台中没有收到任何错误消息。

这是我在 development.rb 中包含的内容:

  config.action_mailer.smtp_settings = {
  address:              'smtp.sendgrid.net',
  port:                 587,
  domain:               'john@anotherpin.com',
  user_name:             'apikey',
  password:              Rails.application.credentials[Rails.env.to_sym][:sendgrid_username],
  authentication:       'plain',
  enable_starttls_auto: true }

我知道,截至 2020 年 4 月,Sendgrid 需要验证发件人才能使用他们的任何服务,所以我已经成功地继续这样做了。尽管如此,我的消息似乎没有发送到测试电子邮件收件箱。

有谁知道为什么我看到它们是在我的终端中发送的,而不是在我的实际收件箱中。

标签: ruby-on-railssendgridsendgrid-rails

解决方案


推荐阅读