Rails ActionMailer使用API方法而非SMTP - SendGrid

3
我正在尝试使用Rails 5.2和Sendgrid发送邮件。我已经阅读了如何设置的教程。然而,我找到的都是设置SMTP方法发送的方式,这种方式比API方法更慢。例如:https://medium.com/le-wagon/how-to-send-email-with-action-mailer-and-sendgrid-in-rails-5-32ed0c9167fd 使用标准的sendgrid gem:https://github.com/sendgrid/sendgrid-ruby 是否有任何方法可以使用action mailer和API方法发送电子邮件?我不想只使用api密钥进行身份验证,我想使用api发送邮件,而不是SMTP。
1个回答

2

没有使用标准的sendgrid gem,但看到了这个gem:

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

它允许action mailer通过将以下内容添加到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
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接