Class: Snails::Mailer::MailgunBackend
- Defined in:
- lib/snails/mailer.rb
Defined Under Namespace
Classes: Attachment
Instance Method Summary collapse
- #deliver(email, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ MailgunBackend
constructor
A new instance of MailgunBackend.
Methods inherited from Backend
Constructor Details
#initialize(options = {}) ⇒ MailgunBackend
Returns a new instance of MailgunBackend.
212 213 214 215 216 |
# File 'lib/snails/mailer.rb', line 212 def initialize( = {}) api_key = [:api_key] domain_name = [:domain_name] @url = "https://api:#{api_key}@api.mailgun.net/v3/#{domain_name}/messages" end |
Instance Method Details
#deliver(email, options = {}) ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/snails/mailer.rb', line 218 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 if email[:attachments] data[:attachment] = email[:attachments].map do |att| Attachment.new(att[:content], att[:filename], att[:content_type]) end end resp = RestClient.post(@url, data) return resp.code == 200 ? [resp.body, data[:to]] : nil end |