【发布时间】: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