Module: Octo::Email

Defined in:
lib/octocore-cassandra/email.rb

Overview

Octo Email Sender

Instance Method Summary collapse

Instance Method Details

#enqueue_msg(message) ⇒ Object

Adding Email details to Resque Queue

Parameters:

  • message (Hash)

    Hash contain message details



42
43
44
# File 'lib/octocore-cassandra/email.rb', line 42

def enqueue_msg(message)
  Resque.enqueue(Octo::EmailSender, message)
end

#send(email, subject, opts = {}) ⇒ Object

Send Emails using mandrill api

Parameters:

  • email (Text)

    Email Address of the receiver

  • subject (Text)

    Subject of Email

  • opt (Hash)

    Hash contain other message details



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/octocore-cassandra/email.rb', line 14

def send(email, subject, opts = {})
  if email.nil? or subject.nil?
    raise ArgumentError, 'Email Address or Subject is missing'
  else
    message = {
      from_name: Octo.get_config(:email_sender).fetch(:name),
      from_email: Octo.get_config(:email_sender).fetch(:email),

      subject: subject,

      text: opts.fetch('text', nil),
      html: opts.fetch('html', nil),

      to: [{
        email: email,
        name: opts.fetch('name', nil)
      }]
    }
    # Pass the message to resque only when mandrill key is present
    _mandrill_config = ENV['MANDRILL_API_KEY'] || Octo.get_config(:mandrill_api_key)
    if _mandrill_config and !_mandrill_config.empty?
      enqueue_msg(message)
    end
  end
end