2

I'm new to using SendGrid with Ruby on Rails. I'm using SendGrid's dynamic template and the sendgrid_actionmailer gem to send emails.

I cannot figure out a way to show previews for these emails (dynamic templates).

In my development.rb file

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

My mailer

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

I also have a view file for this mailer but it's empty as I'm using dynamic template

When I create a mailer preview for this, it does not show the dynamic template, instead the empty view file is rendered.

class TestMailerPreview < ActionMailer::Preview
  def test_notification_preview
    TestMailer.test_notification
  end
end
ssh
  • 41
  • 6

1 Answers1

0

You would need to create a custom preview where you hit sendgrid API for getting the html content of the template and then constructing the preview yourself for that

Harini
  • 1