Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mandrill Template Support #176

Merged
merged 3 commits into from
Jul 1, 2016

Conversation

john-griffin
Copy link
Contributor

Adds the ability to use Mandrill's built in template support. This means template rendering can be fully offloaded to Mandrill. This is done by adding a template function to MandrillHelper that inserts template config into the private params. These params are detected when trying to deliver the email which switches over the API path and inserts params into the request.

Here is an example of how it can be used below. Please note the only new public api is Bamboo.MandrillHelper.template the rest of the config can be done using existing functions.

new_email
|> to("[email protected]")
|> from("[email protected]")
|> Bamboo.MandrillHelper.template("invoice")
|> Bamboo.MandrillHelper.put_param("merge_language", "handlebars")
|> Bamboo.MandrillHelper.put_param("global_merge_vars", [ %{ "name": "reference_number", "content": "ABC001" }])
|> Mailer.deliver_now

Tests are included and this is working against a production Mandrill account. Regular message sending via the API is unaffected by this change.

@@ -91,8 +92,16 @@ defmodule Bamboo.MandrillAdapter do

defp convert_to_mandrill_params(email, api_key) do
%{key: api_key, message: message_params(email)}
|> add_template_params(email)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of calling this maybe_put_template_params. That way it's clear that it sometimes won't add the params

@paulcsmith
Copy link
Contributor

Left a couple comments. This is really cool! Thanks for submitting the PR

Inserts template config into the email to be picked up the adapter.
Template content is required when sending a template so default the
content to empty array.
If a template_name has been set on the email use the template api path
instead of the regular one.
The send-template path requires template_name and template_content be
at the root of the params. If no template, params are not affected.
@john-griffin
Copy link
Contributor Author

@paulcsmith thanks for the awesome feedback! I've incorporated those changes and rebased.

@paulcsmith
Copy link
Contributor

@john-griffin This looks fantastic! Thanks for the PR

@paulcsmith paulcsmith merged commit 717bfa7 into beam-community:master Jul 1, 2016
@maxim
Copy link

maxim commented Aug 14, 2018

Hey folks, there are currently no docs anywhere that provide the snippet at the top of this issue, and if you aren't familiar with all the details of Mandrill, you can spend a bunch of time trying to figure out why the stuff you pass into template_content doesn't get interpolated (hint: it's because you can only use handlebars interpolation with merge_vars and global_merge_vars, but not with template_content, so trying to use template function alone won't work). Just a tiny suggestion that perhaps the snippet at the top of this issue should be added as an example to the function's doc.

@rootkc
Copy link

rootkc commented Apr 21, 2021

@maxim exactly that just happened to me. Thanks for this comment 😄

@germsvel
Copy link
Collaborator

@rootkc if you're up for it, a pull-request to improve the function's documentation would be very welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants