Sha256: 9665de7365f7a4b2e2dabe39808e1c90392eda054b8a62e86fbf22aabb8c0574

Contents?: true

Size: 751 Bytes

Versions: 1

Compression:

Stored size: 751 Bytes

Contents

require "mail"

module DailyWeeklyMonthly
  class Notifier
    def initialize smtp_server, smtp_port
      @smtp_server = smtp_server
      @smtp_port = smtp_port
    end

    # rubocop: disable Metrics/MethodLength
    def call exception, deliver_to
      mail = Mail.new {
        from "backups@localhost"
        to deliver_to
        subject "Backup failed"
        body <<EOF
Backup failure

#{exception.message}

#{exception.backtrace.join("\n")}
EOF
      }
      if @smtp_server && @smtp_port
        mail.delivery_method :smtp, address: @smtp_server,
                                    port: @smtp_port,
                                    enable_starttls_auto: false
      end
      mail.deliver
    end
    # rubocop: enable all
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
daily_weekly_monthly-0.0.4 lib/daily_weekly_monthly/notifier.rb