Class: Feedbook::Notifiers::MailNotifier

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/feedbook/notifiers/mail_notifier.rb

Instance Method Summary collapse

Instance Method Details

#load_configuration(configuration = {}) ⇒ NilClass

Load configuration for MailNotifier

Parameters:

  • configuration (defaults to: {})

    {} [Hash] Configuration hash (required: address, domain, username, password, to, from, subject)

Returns:

  • (NilClass)

    nil



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/feedbook/notifiers/mail_notifier.rb', line 28

def load_configuration(configuration = {})
  options = { address:              configuration.fetch('address'),
              port:                 configuration.fetch('port', 5870),
              domain:               configuration.fetch('domain'),
              user_name:            configuration.fetch('username'),
              password:             configuration.fetch('password'),
              authentication:       configuration.fetch('authentication', 'plain'),
              enable_starttls_auto: configuration.fetch('enable_starttls_auto', true)  }

  @to      = configuration.fetch('to')
  @from    = configuration.fetch('from')
  @subject = configuration.fetch('subject')

  Mail.defaults do
    delivery_method :smtp, options
  end

  puts 'Configuration loaded for MailNotifier'
end

#notify(message) ⇒ NilClass

Sends notification to Mail

Parameters:

  • message (String)

    message to be send via email

Returns:

  • (NilClass)

    nil



13
14
15
16
17
18
19
20
21
22
# File 'lib/feedbook/notifiers/mail_notifier.rb', line 13

def notify(message)
  Mail.deliver do
    to      to
    from    from
    subject subject
    body    message
  end

  puts "New message has been notified on Mail: #{message}"
end