Last active
July 18, 2018 15:43
-
-
Save tiegz/6789111 to your computer and use it in GitHub Desktop.
Getting Mailgun SMTP Batch emails to work in ActionMailer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FoobarMailer < BaseMailer | |
# The method you'll actually call to generate the batched email | |
def batched_foobar | |
# Recipient Variables | |
recipients = {"[email protected]" => {"name" => "You Youington"}} | |
mail(to: "[email protected]") do |format| | |
# Mailgun requires you to base64 your Recipient Variables JSON | |
format.custom('application/json', content_transfer_encoding: "base64") do | |
render text: Base64.encode64(recipients.to_json) | |
end | |
# The standalone email, including both headers and body | |
format.custom('message/rfc822') do | |
render text: FoobarMailer.regular_foobar.to_s | |
end | |
end | |
end | |
# The standalone email... used to generate one part of the batched email | |
def regular_foobar() | |
mail(to: "%recipient%") do |format| | |
format.text { render text: "Hello %recipient.name%" } | |
end | |
end | |
end | |
# Example | |
FoobarMailer.batched_foobar.deliver |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment