class DoSnapshot::Mail

Shared mailer.

Attributes

mailer[W]
opts_default[W]
smtp_default[W]

Public Class Methods

new(options = {}) click to toggle source
# File lib/do_snapshot/mail.rb, line 13
def initialize(options = {})
  options.each { |key, option| send("#{key}=", option) }
end

Public Instance Methods

mailer() click to toggle source
# File lib/do_snapshot/mail.rb, line 22
def mailer
  @mailer ||= Pony.method(:mail)
end
notify() click to toggle source

Sending message via Hash params.

Options

–mail to:mail@somehost.com from:from@host.com –smtp address:smtp.gmail.com user_name:someuser password:somepassword

# File lib/do_snapshot/mail.rb, line 50
def notify
  setup_notify
  logger.debug 'Sending e-mail notification.'
  # Look into your inbox :)
  mailer.call(opts)
end
opts() click to toggle source
# File lib/do_snapshot/mail.rb, line 30
def opts
  @opts ||= opts_default.dup
end
opts=(options) click to toggle source
# File lib/do_snapshot/mail.rb, line 40
def opts=(options)
  options.each_pair do |key, value|
    opts[key.to_sym] = value
  end if options
end
reset_options() click to toggle source
# File lib/do_snapshot/mail.rb, line 17
def reset_options
  @opts = opts_default
  @smtp = smtp_default
end
smtp() click to toggle source
# File lib/do_snapshot/mail.rb, line 26
def smtp
  @smtp ||= smtp_default.dup
end
smtp=(options) click to toggle source
# File lib/do_snapshot/mail.rb, line 34
def smtp=(options)
  options.each_pair do |key, value|
    smtp[key.to_sym] = value
  end if options
end

Protected Instance Methods

logger() click to toggle source
# File lib/do_snapshot/mail.rb, line 59
def logger
  DoSnapshot::Helpers::UniversalLogger
end
opts_default() click to toggle source
# File lib/do_snapshot/mail.rb, line 63
def opts_default
  @opts_default ||= {
    subject: 'Digital Ocean: maximum snapshots is reached.',
    body: "Please cleanup your Digital Ocean account.\nSnapshot maximum is reached.",
    from: 'noreply@someonelse.com',
    to: 'to@someonelse.com',
    via: :smtp
  }
end
setup_notify() click to toggle source
# File lib/do_snapshot/mail.rb, line 80
def setup_notify
  opts[:body] = "#{opts[:body]}\n\nTrace: #{DateTime.now}\n#{DoSnapshot.logger.buffer.join("\n")}"
  opts[:via_options] = smtp
end
smtp_default() click to toggle source
# File lib/do_snapshot/mail.rb, line 73
def smtp_default
  @smtp_default ||= {
    domain: 'localhost.localdomain',
    port: '25'
  }
end