Skip to content

Instantly share code, notes, and snippets.

@ivobenedito
Created April 21, 2016 09:54
Show Gist options
  • Select an option

  • Save ivobenedito/cca931f72f787bbaf872e0b6571cdb3f to your computer and use it in GitHub Desktop.

Select an option

Save ivobenedito/cca931f72f787bbaf872e0b6571cdb3f to your computer and use it in GitHub Desktop.
Mandrill Mailer
class BaseMandrillMailer < ActionMailer::Base
default(
from: ENV.fetch('SUPPORT_EMAIL'),
reply_to: ENV.fetch('SUPPORT_EMAIL')
)
private
def send_mail(email, subject, body)
mail(to: email, subject: subject, body: body, content_type: 'text/html')
end
def mandrill_template(template_name, attributes)
vars = merge_vars(attributes)
response = mandrill_client.templates.render(template_name, [], vars)
response['html']
end
def merge_vars(attributes)
attributes.collect do |key, value|
{ name: key, content: value }
end
end
def mandrill_client
@mandrill_client ||= Mandrill::API.new(ENV.fetch('SMTP_PASSWORD'))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment