Created
April 21, 2016 09:54
-
-
Save ivobenedito/cca931f72f787bbaf872e0b6571cdb3f to your computer and use it in GitHub Desktop.
Mandrill Mailer
This file contains hidden or 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 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