The PostmarkRails::TemplatedMailerMixin allows you to use Postmark templates within your Rails mailers. When included in a mailer, it automatically manages the message body and subject to reflect the template being used.
To use it, include the mixin in your mailer class. You can then set the template_model (the data passed to the template) directly on the mailer instance.
Important Constraints:
- You cannot manually override the
body, content_type, or subject headers in a templated mailer. Attempting to do so will raise an ArgumentError. - The mailer uses a
postmark_template_alias to identify which Postmark template to use.
class MyMailer < ActionMailer::Base
include PostmarkRails::TemplatedMailerMixin
def welcome_email(user)
@user = user
# Set the data to be passed to the Postmark template
template_model = { name: user.name, email: user.email }
# The template_alias is typically derived from the action_name
mail(template_model: template_model)
end
end