Sha256: 9b52378cda261fb784495b452f80798ae76e10008c1d3caf8327207f0af00f1b

Contents?: true

Size: 1.14 KB

Versions: 9

Compression:

Stored size: 1.14 KB

Contents

require 'pony'

module LetsencryptWebfaction
  class Emailer
    SUBJECT_MESSAGE = 'New certificate installation'.freeze

    def initialize(instructions, support_email: '', account_email: '', notification_email: '', email_configuration: {})
      @instructions = instructions

      raise Error, 'Missing account_email' if account_email == '' || account_email.nil?
      raise Error, 'Missing notification_email' if notification_email == '' || notification_email.nil?

      @support_email = support_email
      @account_email = account_email
      @notification_email = notification_email

      Pony.options = email_configuration
    end

    def send!
      send_to_support!
      send_to_account!
    end

    def send_to_support!
      return if @support_email.nil? || @support_email == ''
      Pony.mail(to: @support_email, from: @account_email, subject: SUBJECT_MESSAGE, body: @instructions.instructions)
    end

    def send_to_account!
      Pony.mail(to: @notification_email, from: @notification_email, subject: SUBJECT_MESSAGE, body: @instructions.full_message(support_email: @support_email != ''))
    end

    class Error < StandardError; end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
letsencrypt_webfaction-1.1.8 lib/letsencrypt_webfaction/emailer.rb
letsencrypt_webfaction-1.1.7 lib/letsencrypt_webfaction/emailer.rb
letsencrypt_webfaction-1.1.6 lib/letsencrypt_webfaction/emailer.rb
letsencrypt_webfaction-1.1.5 lib/letsencrypt_webfaction/emailer.rb
letsencrypt_webfaction-1.1.4 lib/letsencrypt_webfaction/emailer.rb
letsencrypt_webfaction-1.1.3 lib/letsencrypt_webfaction/emailer.rb
letsencrypt_webfaction-1.1.2 lib/letsencrypt_webfaction/emailer.rb
letsencrypt_webfaction-1.1.1 lib/letsencrypt_webfaction/emailer.rb
letsencrypt_webfaction-1.1.0 lib/letsencrypt_webfaction/emailer.rb