Class: Ruport::Mailer
- Inherits:
-
Object
- Object
- Ruport::Mailer
- Extended by:
- Forwardable
- Defined in:
- lib/ruport/util/mailer.rb
Overview
Overview
This class uses SMTP to provide a simple mail sending mechanism. It also uses MailFactory to provide attachment and HTML email support.
Defined Under Namespace
Classes: InvalidMailerConfigurationError
Class Method Summary collapse
-
.add_mailer(name, options) ⇒ Object
:call-seq: add_mailer(mailer_name, options).
-
.default_mailer ⇒ Object
Alias for
mailers[:default]
. -
.mailers ⇒ Object
Returns all the
mailer
s defined.
Instance Method Summary collapse
-
#deliver(options = {}) ⇒ Object
Sends the message.
-
#initialize(mailer_label = :default) ⇒ Mailer
constructor
Creates a new Mailer object.
Constructor Details
#initialize(mailer_label = :default) ⇒ Mailer
32 33 34 35 36 37 |
# File 'lib/ruport/util/mailer.rb', line 32 def initialize( mailer_label=:default ) select_mailer(mailer_label) mail_object.from = @mailer.address if mail_object.from.to_s.empty? rescue raise "you need to specify a mailer to use" end |
Class Method Details
.add_mailer(name, options) ⇒ Object
:call-seq:
add_mailer(mailer_name, )
Creates or retrieves a mailer configuration. Available options:
:host
-
The SMTP host to use.
:address
-
Address the email is being sent from.
:user
-
The username to use on the SMTP server
:password
-
The password to use on the SMTP server. Optional.
:port
-
The SMTP port to use. Optional, defaults to 25.
:auth_type
-
SMTP authorization method. Optional, defaults to
:plain
. :mail_class
-
If you don’t want to use the default
MailFactory
object, you can pass another mailer to use here.
Example (creating a mailer config):
add_mailer :alternate, :host => "mail.test.com",
:address => "[email protected]",
:user => "test",
:password => "blinky"
:auth_type => :cram_md5
Example (retreiving a mailer config):
mail_conf = mailers[:alternate] #=> <OpenStruct ..>
mail_conf.address #=> [email protected]
72 73 74 75 |
# File 'lib/ruport/util/mailer.rb', line 72 def add_mailer(name,) mailers[name] = OpenStruct.new() check_mailer(mailers[name],name) end |
.default_mailer ⇒ Object
Alias for mailers[:default]
.
78 79 80 |
# File 'lib/ruport/util/mailer.rb', line 78 def default_mailer mailers[:default] end |
.mailers ⇒ Object
Returns all the mailer
s defined
83 |
# File 'lib/ruport/util/mailer.rb', line 83 def mailers; @mailers ||= {}; end |
Instance Method Details
#deliver(options = {}) ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/ruport/util/mailer.rb', line 101 def deliver(={}) to = .delete(:to) mail_object.to = Array(to).join(",") .each { |k,v| send("#{k}=",v) if respond_to? "#{k}=" } Net::SMTP.start(@host,@port,@host,@user,@password,@auth) do |smtp| smtp.(([:mail_object] || mail_object).to_s, [:from], to) end end |