Class: Users::EmailHelper

Inherits:
Object show all
Includes:
Singleton
Defined in:
lib/users/email_helper.rb

Overview

Helper singleton class to assist in sending emails.

Config options collapse

Config options collapse

Instance Method Summary collapse

Constructor Details

#initializeEmailHelper

Returns a new instance of EmailHelper


42
43
# File 'lib/users/email_helper.rb', line 42

def initialize
end

Class Attribute Details

.email_enabledObject

Boolean toggling email subsystem


20
21
22
# File 'lib/users/email_helper.rb', line 20

def email_enabled
  @email_enabled
end

.smtp_from_addressObject

From address to set on outgoing smtp messages


28
29
30
# File 'lib/users/email_helper.rb', line 28

def smtp_from_address
  @smtp_from_address
end

.smtp_hostObject

String smtp host to connect to


24
25
26
# File 'lib/users/email_helper.rb', line 24

def smtp_host
  @smtp_host
end

Class Method Details

.set_config(config) ⇒ Object

Set config options using Omega::Config instance

Parameters:


33
34
35
36
37
# File 'lib/users/email_helper.rb', line 33

def set_config(config)
  self.email_enabled     = config.email_enabled
  self.smtp_host         = config.smtp_host
  self.smtp_from_address = config.smtp_from_address
end

Instance Method Details

#send_email(to_address, message) ⇒ Object

Send message to specified address

Parameters:

  • to_address (String)

    e-mail address to send message to

  • message (String)

    body of message to email


49
50
51
52
53
54
55
56
# File 'lib/users/email_helper.rb', line 49

def send_email(to_address, message)
  if self.class.email_enabled
    Net::SMTP.start(self.class.smtp_host) do |smtp|
      smtp.send_message message, self.class.smtp_from_address, to_address
    end
  end
  nil
end