Class: Helper::Mail

Inherits:
Object
  • Object
show all
Defined in:
lib/depengine/helper/mail.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMail

Returns a new instance of Mail.



7
8
9
10
# File 'lib/depengine/helper/mail.rb', line 7

def initialize
  smtp_host ||= 'localhost'
  smtp_port ||= 25
end

Instance Attribute Details

#smtp_hostObject

Returns the value of attribute smtp_host.



5
6
7
# File 'lib/depengine/helper/mail.rb', line 5

def smtp_host
  @smtp_host
end

#smtp_portObject

Returns the value of attribute smtp_port.



5
6
7
# File 'lib/depengine/helper/mail.rb', line 5

def smtp_port
  @smtp_port
end

Instance Method Details

#sendmail(options = {}) ⇒ Object

Sends an email via smtp.

Parameters:

  • options - a hash with needed configuration options for the email

    • :from - the senders address

    • :to - the recipiants address

    • :subject - the email subject

    • :body - the actual text to send in the mail



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/depengine/helper/mail.rb', line 20

def sendmail(options={})
  begin
    Pony.mail( \
      :from => options[:from],
      :to => options[:to],
      :via => :smtp,
      :via_options => {
        :address              => smtp_host,
        :port                 => smtp_port,
        :authentication       => nil,
        :enable_starttls_auto => false
      },
      :subject => options[:subject],
      :body    => options[:body]
    )
  rescue Exception => e
    $log.writer.error "Can not send mail via host #{smtp_host}"
    $log.writer.error e.message
  end
end