Class: Padrino::Mailer::Base
- Defined in:
- padrino-mailer/lib/padrino-mailer/base.rb
Overview
This is the abstract class that other mailers will inherit from in order to send mail.
You can set the default delivery settings from your app through:
set :delivery_method, :smtp => {
:address => 'smtp.yourserver.com',
:port => '25',
:user_name => 'user',
:password => 'pass',
:authentication => :plain
}
or sendmail:
set :delivery_method, :sendmail
or for tests:
set :delivery_method, :test
and all delivered mail will use these settings unless otherwise specified.
Define a mailer in your application:
# app/mailers/sample_mailer.rb
MyAppName.mailers :sample do
defaults :content_type => 'html'
email :registration do |name, age|
to '[email protected]'
from '[email protected]'
subject 'Welcome to the site!'
locals :name => name
render 'registration'
end
end
Use the mailer to deliver messages:
deliver(:sample, :registration, "Bob", "21")
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#delivery_settings ⇒ Object
Returns the value of attribute delivery_settings.
-
#mailer_name ⇒ Object
Returns the value of attribute mailer_name.
-
#messages ⇒ Object
Returns the value of attribute messages.
Instance Method Summary collapse
-
#defaults(attributes = nil) ⇒ Object
Defines the default attributes for a message in this mailer (including app-wide defaults).
-
#email(name, &block) ⇒ Object
(also: #message)
Defines a mailer object allowing the definition of various email messages that can be delivered.
-
#initialize(app, name, &block) ⇒ Base
constructor
Constructs a
Mailer
base object with specified options.
Constructor Details
#initialize(app, name, &block) ⇒ Base
Constructs a Mailer
base object with specified options.
58 59 60 61 62 63 64 |
# File 'padrino-mailer/lib/padrino-mailer/base.rb', line 58 def initialize(app, name, &block) @mailer_name = name @messages = {} @defaults = {} @app = app instance_eval(&block) end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
45 46 47 |
# File 'padrino-mailer/lib/padrino-mailer/base.rb', line 45 def app @app end |
#delivery_settings ⇒ Object
Returns the value of attribute delivery_settings.
45 46 47 |
# File 'padrino-mailer/lib/padrino-mailer/base.rb', line 45 def delivery_settings @delivery_settings end |
#mailer_name ⇒ Object
Returns the value of attribute mailer_name.
45 46 47 |
# File 'padrino-mailer/lib/padrino-mailer/base.rb', line 45 def mailer_name @mailer_name end |
#messages ⇒ Object
Returns the value of attribute messages.
45 46 47 |
# File 'padrino-mailer/lib/padrino-mailer/base.rb', line 45 def @messages end |
Instance Method Details
#defaults(attributes = nil) ⇒ Object
Defines the default attributes for a message in this mailer (including app-wide defaults).
109 110 111 112 113 114 115 |
# File 'padrino-mailer/lib/padrino-mailer/base.rb', line 109 def defaults(attributes=nil) if attributes.nil? # Retrieve the default values @app.respond_to?(:mailer_defaults) ? @app.mailer_defaults.merge(@defaults) : @defaults else # updates the default values @defaults = attributes end end |
#email(name, &block) ⇒ Object Also known as: message
Defines a mailer object allowing the definition of various email messages that can be delivered.
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'padrino-mailer/lib/padrino-mailer/base.rb', line 83 def email(name, &block) raise "The email '#{name}' is already defined" if self.[name] self.[name] = Proc.new { |*attrs| = app.settings._padrino_mailer::Message.new(self.app) .mailer_name = mailer_name . = name .defaults = self.defaults if self.defaults.any? .delivery_method(*delivery_settings) .instance_exec(*attrs, &block) } end |