Sha256: e7d7b35472d31d9abdd36bf33621e05ca9a659fe67600198e324ea891040b990

Contents?: true

Size: 1.18 KB

Versions: 4

Compression:

Stored size: 1.18 KB

Contents

require 'sinatra/base'
require 'sinatra_more'
require 'haml'

class MailerDemo < Sinatra::Base
  configure do
    set :root, File.dirname(__FILE__)
    set :smtp_settings, {
      :host   => 'smtp.gmail.com',
      :port   => '587',
      :tls    => true,
      :user   => 'user',
      :pass   => 'pass',
      :auth   => :plain
   }
  end

  register Sinatra::MailerPlugin

  class SampleMailer < Sinatra::MailerPlugin::MailerBase
    def birthday_message(name, age)
      subject "Happy Birthday!"
      to   'john@fake.com'
      from 'noreply@birthday.com'
      body 'name' => name, 'age' => age
      via  :smtp
    end

    def anniversary_message(names, years_married)
      subject "Happy anniversary!"
      to   'julie@fake.com'
      from 'noreply@anniversary.com'
      body 'names' => names, 'years_married' => years_married
      type 'html'
    end
  end

  post "/deliver/plain" do
    result = SampleMailer.deliver_birthday_message("Joey", 21)
    result ? "mail delivered" : 'mail not delivered'
  end

  post "/deliver/html" do
    result = SampleMailer.deliver_anniversary_message("Joey & Charlotte", 16)
    result ? "mail delivered" : 'mail not delivered'
  end
end

class MailerUser

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
darkhelmet-sinatra_more-0.3.36 test/fixtures/mailer_app/app.rb
darkhelmet-sinatra_more-0.3.35 test/fixtures/mailer_app/app.rb
darkhelmet-sinatra_more-0.3.34 test/fixtures/mailer_app/app.rb
darkhelmet-sinatra_more-0.3.33 test/fixtures/mailer_app/app.rb