class GrapeTokenAuth::Mail::SMTPMailer

Attributes

email[R]
message[R]
opts[R]
to_address[R]

Public Class Methods

new(message, opts) click to toggle source
# File lib/grape_token_auth/mail/smtp_mailer.rb, line 5
def initialize(message, opts)
  @message = message
  @opts = opts
  @to_address = opts[:to] || opts['to']
end
send!(message, options) click to toggle source
# File lib/grape_token_auth/mail/smtp_mailer.rb, line 26
def self.send!(message, options)
  new(message, options).prepare_email!.send_mail
end

Public Instance Methods

prepare_email!() click to toggle source
# File lib/grape_token_auth/mail/smtp_mailer.rb, line 16
def prepare_email!
  @email = ::Mail.new
  @email.to = to_address
  @email.subject = message.subject
  @email.from = GrapeTokenAuth.configuration.from_address
  @email.text_part = prepare_text
  @email.html_part = prepare_html
  self
end
send_mail() click to toggle source
# File lib/grape_token_auth/mail/smtp_mailer.rb, line 11
def send_mail
  set_smtp_config
  email.deliver
end
valid_options?() click to toggle source
# File lib/grape_token_auth/mail/smtp_mailer.rb, line 30
def valid_options?
  return false unless to_address
  true
end

Protected Instance Methods

prepare_html() click to toggle source
# File lib/grape_token_auth/mail/smtp_mailer.rb, line 43
def prepare_html
  part = ::Mail::Part.new
  part.body = message.html_body
  part
end
prepare_text() click to toggle source
# File lib/grape_token_auth/mail/smtp_mailer.rb, line 49
def prepare_text
  part = ::Mail::Part.new
  part.body = message.text_body
  part
end
set_smtp_config() click to toggle source
# File lib/grape_token_auth/mail/smtp_mailer.rb, line 37
def set_smtp_config
  config = GrapeTokenAuth.configuration.smtp_configuration
  return if config.empty?
  email.delivery_method(:smtp, config)
end