W3cubDocs

/Padrino

Class: Padrino::Mailer::Base

Inherits:
Object
  • Object

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

Instance Method Summary

Constructor Details

#initialize(app, name, &block) ⇒ Base

Constructs a Mailer base object with specified options.

Parameters:

  • app (Sinatra::Application) — The application tied to this mailer.
  • name (Symbol) — The name of this mailer.
  • block (Proc) — The email definitions block.

See Also:

Instance Attribute Details

#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 Details

#defaults(attributes = nil) ⇒ Object

Defines the default attributes for a message in this mailer (including app-wide defaults).

Examples:

mailer :alternate do
  defaults :from => '[email protected]', :to => '[email protected]'
  email(:foo) do; end
end

Parameters:

  • attributes (Hash) (defaults to: nil) — The hash of message options to use as default.

#email(name, &block) ⇒ Object Also known as: message

Defines a mailer object allowing the definition of various email messages that can be delivered.

Examples:

email :birthday do |name, age|
  subject "Happy Birthday!"
  to   '[email protected]'
  from '[email protected]'
  locals 'name' => name, 'age' => age
  render 'birthday'
end

Parameters:

  • name (Symbol) — The name of this email message.
  • block (Proc) — The message definition (i.e subject, to, from, locals).

© 2010–2019 Padrino
Licensed under the MIT License.
https://www.rubydoc.info/github/padrino/padrino-framework/Padrino/Mailer/Base