Class: Henry::EmailClient

Inherits:
Object
  • Object
show all
Defined in:
lib/henry/email_client.rb

Overview

Email client to send reports by email

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.send_file(file_path, recipients, subject = '') ⇒ True, False

Sends a file by email (fails silentl).

Parameters:

  • file_path (String)

    the path of he target file.

  • recipients (<String>)

    the list of recipients.

  • sebject (String)

    the email subject (optional).

Returns:

  • (True, False)

    whenever the task ends successfully or not.



25
26
27
28
29
30
31
32
# File 'lib/henry/email_client.rb', line 25

def self.send_file(file_path, recipients, subject='')
  begin
    self.send_file!(file_path, recipients, subject)
    return true
  rescue Net::SMTPUnknownError, Net::SMTPAuthenticationError
    return false
  end
end

.send_file!(file_path, recipients, subject = '') ⇒ Object

Sends a file by email (rise exeption on error).

Parameters:

  • file_path (String)

    the path of he target file.

  • recipients (<String>)

    the list of recipients.

  • sebject (String)

    the email subject (optional).



39
40
41
42
43
44
45
46
# File 'lib/henry/email_client.rb', line 39

def self.send_file!(file_path, recipients, subject='')
  Mail.deliver do
    from 'Henry Reports <[email protected]>'
    bcc recipients.join(',')
    subject subject
    add_file file_path
  end
end

.send_message(message, recipients, subject = '') ⇒ True, False

Sends a message by email (fails silently).

Parameters:

  • message (String)

    the message to be sent.

  • recipients (<String>)

    the list of recipients.

  • sebject (String)

    the email subject (optional).

Returns:

  • (True, False)

    whenever the task ends successfully or not.



54
55
56
57
58
59
60
61
# File 'lib/henry/email_client.rb', line 54

def self.send_message(message, recipients, subject='')
  begin
    self.send_message!(message, recipients, subject)
    return true
  rescue Net::SMTPUnknownError, Net::SMTPAuthenticationError
    return false
  end
end

Instance Method Details

#send_message!(message, recipients, subject = '') ⇒ Object

Sends a message by email (rise exception on error).

Parameters:

  • message (String)

    the message to be sent.

  • recipients (<String>)

    the list of recipients.

  • sebject (String)

    the email subject (optional).



68
69
70
71
72
73
74
75
# File 'lib/henry/email_client.rb', line 68

def send_message!(message, recipients, subject='')
  Mail.deliver do
    from 'Henry Reports <[email protected]>' 
    bcc recipients.join(',')
    subject subject
    body message
  end
end