Class: Snitch::Services::Email
- Inherits:
-
Snitch::Service
- Object
- Snitch::Service
- Snitch::Services::Email
- Defined in:
- lib/snitch/services/email.rb
Instance Attribute Summary
Attributes inherited from Snitch::Service
Instance Method Summary collapse
- #create_email(message) ⇒ Object
-
#initialize(*args) ⇒ Email
constructor
A new instance of Email.
- #lookup(var) ⇒ Object
- #send_email(email) ⇒ Object
-
#tattle(message) ⇒ Object
Sends the email.
Methods inherited from Snitch::Service
#method_missing, new_from_name
Constructor Details
#initialize(*args) ⇒ Email
Returns a new instance of Email.
12 13 14 |
# File 'lib/snitch/services/email.rb', line 12 def initialize(*args) super(*args) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Snitch::Service
Instance Method Details
#create_email(message) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/snitch/services/email.rb', line 29 def create_email() mail = TMail::Mail.new mail.to = to mail.from = from mail.subject = [0, .index("\n") || .length] mail.date = Time.now mail.set_content_type 'text', 'plain' mail.body = mail end |
#lookup(var) ⇒ Object
40 41 42 43 44 |
# File 'lib/snitch/services/email.rb', line 40 def lookup(var) self.send(var) rescue NameError nil end |
#send_email(email) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/snitch/services/email.rb', line 21 def send_email(email) email_opts = %W(server port host login password auth_method).collect { |attr| lookup(attr) } Net::SMTP.start(*email_opts) do |smtp| smtp.(email.to_s, from, to) end end |
#tattle(message) ⇒ Object
Sends the email
17 18 19 |
# File 'lib/snitch/services/email.rb', line 17 def tattle() send_email(create_email()) end |