如何创建SendGrid动态模板Ruby on Rails的电子邮件预览



我刚开始用Ruby on Rails使用SendGrid。我使用SendGrid的动态模板和sendgrid_actionmailer gem来发送电子邮件。

我想不出一个方法来显示这些电子邮件的预览(动态模板)。

在我的发展。rb文件

if ENV['sendgrid_api_key']
config.action_mailer.delivery_method = :sendgrid_actionmailer
config.action_mailer.sendgrid_actionmailer_settings = {
api_key: ENV['sendgrid_api_key']
}
end

我梅勒

class TestMailer < ApplicationMailer
layout false
def test_notification
mail(to: 'test@example.com',
dynamic_template_data: {
emailBody: 'This is a test email',
},
template_id: 'd-XXXXX')
end
end

我也有一个这个邮件的视图文件但是它是空的,因为我使用的是动态模板

当我为此创建邮件预览时,它不显示动态模板,而是呈现空视图文件。

class TestMailerPreview < ActionMailer::Preview
def test_notification_preview
TestMailer.test_notification
end
end

你需要创建一个自定义预览,点击sendgrid API获取模板的html内容,然后自己构建预览

最新更新