Module: Padrino::Mailer

Defined in:
padrino-mailer/lib/padrino-mailer.rb,
padrino-mailer/lib/padrino-mailer/base.rb,
padrino-mailer/lib/padrino-mailer/mime.rb,
padrino-mailer/lib/padrino-mailer/helpers.rb

Overview

This component uses the mail library to create a powerful but simple mailer within Padrino (and Sinatra). There is full support for using plain or html content-types as well as for file attachments.

Using the mailer in Padrino has two forms. The ‘quick’ method requires only use of the email method directly in the controller:

# app/controllers/session.rb
post :create do
  email do
    from "[email protected]"
    to "[email protected]"
    subject "Welcome!"
    body render('email/registered')
  end
end

Defined Under Namespace

Modules: Helpers, Mime Classes: Base

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object Also known as: included

Registers the Padrino::Mailer helpers with the application.

Examples:

require 'padrino-mailer'
class Demo < Padrino::Application
  register Padrino::Mailer::Helpers
end

Parameters:

  • app (Sinatra::Application)

    The application that needs mailers.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'padrino-mailer/lib/padrino-mailer.rb', line 39

def registered(app)
  require 'padrino-mailer/base'
  require 'padrino-mailer/helpers'
  require 'padrino-mailer/mime'
  # This lazily loads the mail gem, due to its long require time.
  app.set :_padrino_mailer, proc {
    require 'padrino-mailer/ext'
    app._padrino_mailer = Mail
  }
  app.helpers Padrino::Mailer::Helpers
  unless app.respond_to?(:mailer)
    app.send(:extend, Padrino::Mailer::Helpers::ClassMethods)
  end
end