class Email::Delivery::MailgunClient
Public Class Methods
new()
click to toggle source
# File lib/email/delivery/mailgrun_client.rb, line 14 def initialize @api_url = "https://api:#{ENV['MAILGUN_API_KEY']}@#{ENV['MAILGUN_API_URL']}" end
Public Instance Methods
dispatch(from, to, cc, bcc, subject, body)
click to toggle source
# File lib/email/delivery/mailgrun_client.rb, line 18 def dispatch(from, to, cc, bcc, subject, body) response = RestClient.post @api_url, payload(from, to, cc, bcc, subject, body) { status: response.code, message: response.description } end
payload(from, to, cc, bcc, subject, body)
click to toggle source
# File lib/email/delivery/mailgrun_client.rb, line 27 def payload(from, to, cc, bcc, subject, body) data = {} data[:from] = sandbox_from data[:to] = to data[:subject] = subject data[:text] = body unless cc.nil? data[:cc] = cc end unless bcc.nil? data[:bcc] = bcc end data end
sandbox_from()
click to toggle source
Requires a custom domain setup app.mailgun.com/app/domains/new to manage custom 'from'
# File lib/email/delivery/mailgrun_client.rb, line 45 def sandbox_from "Mailgun Sandbox <postmaster@sandboxd76a53e1a7614050ad917bab34226253.mailgun.org>" end