【问题标题】:Using ActionMailer RoR templates with Sendgrid API v3将 ActionMailer RoR 模板与 Sendgrid API v3 一起使用
【发布时间】:2018-06-19 01:19:30
【问题描述】:

我已将 sendgrid-ruby gem 集成到我的 rails 应用程序中,并尝试发送我以前通过 ActionMailer 发送的电子邮件。我使用了 sendgrid 中的示例:

from = Email.new(email: 'test@example.com', name: 'Test Sender')
to = Email.new(email: 'test@example.com')
subject = 'This is a sendgrid test email'
content = Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby')
mail = Mail.new(from, subject, to, content)

sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
response = sg.client.mail._('send').post(request_body: mail.to_json)

但是,我想用我在 Rails 中使用的旧邮件模板替换内容。这可能吗?

【问题讨论】:

  • 如何将邮件模板与 sg.client.mail._('send').post(request_body: mail.to_json) 一起使用?
  • @slindsey3000 这就是我想知道的是否可能。我最终使用了 SMTP,如下所述

标签: ruby-on-rails actionmailer sendgrid-api-v3


【解决方案1】:

您可以使用他们的 SMTP API,它允许您在您的 rails 应用程序中定义或使用您的电子邮件模板。

示例send guild ruby

【讨论】:

  • 感谢您的澄清。你知道是否有办法通过他们的 web api 做到这一点,或者这是不好的做法?
  • 据我所知,这不是一个坏习惯。他们的 web api 允许您在托管服务(如(Mandril)上使用模板)另一方面,通过他们的 SMTP,您可以使用现有模板
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-05
相关资源
最近更新 更多