bamboo v0.8.0 Bamboo.MandrillHelper

Functions for using features specific to Mandrill e.g. tagging, merge vars, templates

Summary

Functions

Set merge_vars that are used by Mandrill

Put extra message parameters that are used by Mandrill

Set a single tag or multiple tags for an email

Send emails using Mandrill’s template API

Functions

put_merge_vars(email, enumerable, fun)

Set merge_vars that are used by Mandrill

Example

email
|> put_merge_vars(users, fn(user) -> %{first_name: user.first_name} end)

A convenience function for:

email
|> put_param(email, "merge_vars", [
  %{
    rcpt: "user1@example.com",
    vars: [
      %{
        "name": "full_name",
        "content": "User 1"
      }
    ]
  },
  %{
    rcpt: "user2@example.com",
    vars: [
      %{
        "name": "full_name",
        "content": "User 2"
      }
    ]
  }
])
put_param(email, key, value)

Put extra message parameters that are used by Mandrill

Parameters set with this function are sent to Mandrill when used along with the Bamboo.MandrillAdapter. You can set things like important, merge_vars, and whatever else you need that the Mandrill API supports.

Example

email
|> put_param(email, "track_opens", true)
|> put_param(email, "merge_vars", [
  %{
    rcpt: "recipient.email@example.com",
    vars: [
      %{
        "name": "first_name",
        "content": "John Doe"
      }
    ]
  }
])
tag(email, tags)

Set a single tag or multiple tags for an email.

A convenience function for put_param(email, "tags", ["my-tag"])

Example

tag(email, "welcome-email")
tag(email, ["welcome-email", "marketing"])
template(email, template_name, template_content \\ [])

Send emails using Mandrill’s template API.

Setup Mandrill to send using a named template with template content. Use this in conjuction with merge vars to offload template rendering to Mandrill. The template name specified here must match the template name stored in Mandrill. Mandrill’s API docs for this can be found here.

Example

template(email, "welcome")
template(email, "welcome", [%{"name" => "Name", "content" => "John"}])