class Backup::Notifier::Ses

Attributes

access_key_id[RW]

Amazon Simple Email Service (SES) Credentials

bcc[RW]

BCC receiver Email Address

cc[RW]

CC receiver Email Address

from[RW]

Sender Email Address

region[RW]

SES Region

reply_to[RW]

Set reply to email address

secret_access_key[RW]

Amazon Simple Email Service (SES) Credentials

send_log_on[RW]

Array of statuses for which the log file should be attached.

Available statuses are: ‘:success`, `:warning` and `:failure`. Default: [:warning, :failure]

to[RW]

Receiver Email Address

Public Class Methods

new(model, &block) click to toggle source
Calls superclass method Backup::Notifier::Base::new
# File lib/backup/notifier/ses.rb, line 34
def initialize(model, &block)
  super
  instance_eval(&block) if block_given?

  @region ||= "eu-west-1"
  @send_log_on ||= [:warning, :failure]
end

Private Instance Methods

client() click to toggle source
# File lib/backup/notifier/ses.rb, line 51
def client
  AWS::SES::Base.new(
    access_key_id: access_key_id,
    secret_access_key: secret_access_key,
    server: "email.#{region}.amazonaws.com"
  )
end
notify!(status) click to toggle source

Notify the user of the backup operation results.

‘status` indicates one of the following:

‘:success` : The backup completed successfully. : Notification will be sent if `on_success` is `true`.

‘:warning` : The backup completed successfully, but warnings were logged. : Notification will be sent, including a copy of the current : backup log, if `on_warning` or `on_success` is `true`.

‘:failure` : The backup operation failed. : Notification will be sent, including a copy of the current : backup log, if `on_failure` is `true`.

# File lib/backup/notifier/ses.rb, line 78
def notify!(status)
  email = ::Mail.new
  email.to       = to
  email.from     = from
  email.cc       = cc
  email.bcc      = bcc
  email.reply_to = reply_to
  email.subject  = message.call(model, status: status_data_for(status))

  send_log = send_log_on.include?(status)
  template = Backup::Template.new(model: model, send_log: send_log)
  email.body = template.result(sprintf("notifier/mail/%s.erb", status.to_s))

  if send_log
    email.convert_to_multipart
    email.attachments["#{model.time}.#{model.trigger}.log"] = {
      mime_type: "text/plain;",
      content: Logger.messages.map(&:formatted_lines).flatten.join("\n")
    }
  end

  client.send_raw_email(email)
end