Class: Snails::Mailer::Mailgun
Instance Method Summary collapse
- #deliver(email, options = {}) ⇒ Object
-
#initialize(api_key:, domain_name:) ⇒ Mailgun
constructor
A new instance of Mailgun.
Methods inherited from Backend
Constructor Details
#initialize(api_key:, domain_name:) ⇒ Mailgun
Returns a new instance of Mailgun.
175 176 177 178 |
# File 'lib/snails/mailer.rb', line 175 def initialize(api_key:, domain_name:) @key = api_key @url = "https://api.mailgun.net/v3/#{domain_name}/messages" end |
Instance Method Details
#deliver(email, options = {}) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/snails/mailer.rb', line 180 def deliver(email, = {}) raise "No body!" if email[:body].nil? data = { from: email[:from], to: email[:to], subject: email[:subject], } data[:text] = email[:body] if email[:body] data[:html] = email[:html_body] if email[:html_body] if data[:text].blank? && data[:html].blank? raise ArgumentError, "Either text or html required" end opts = { username: 'api', password: @key } resp = Dagger.post(@url, data, opts) resp.ok? ? [resp.data, data[:to]] : nil end |