Rails ActionMailer 使用 API 方法而不是 SMTP - SendGrid



我正在尝试使用 Rails 5.2 和 Sendgrid 发送邮件。 我已经阅读了如何设置它的教程。但是,我找到的只是设置SMTP发送方法的方法,该方法比API方法慢。 示例:https://medium.com/le-wagon/how-to-send-email-with-action-mailer-and-sendgrid-in-rails-5-32ed0c9167fd

使用标准发送网格 Gem:https://github.com/sendgrid/sendgrid-ruby

无论如何可以使用操作邮件程序和API方法发送电子邮件吗?我不想只使用 api 密钥进行身份验证,我想使用 api 而不是 SMTP 发送邮件。

不使用标准的 sendgrid gem,但确实看到了这个 gem:

https://github.com/eddiezane/sendgrid-actionmailer

这允许操作邮件程序通过将以下内容添加到config/environments/production.rb来使用 API 方法:

config.action_mailer.delivery_method = :sendgrid_actionmailer
config.action_mailer.sendgrid_actionmailer_settings = {
api_key: ENV['SENDGRID_API_KEY'],
raise_delivery_errors: true
}

最新更新