Skip to content

Send emails from Sinatra in a very simple way (rewriting as Sinatra 0.9.1+ extension)

License

Notifications You must be signed in to change notification settings

kusor/sinatra_mailer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sinatra::Mailer

Adds an email method to your email handlers, that receives a hash of values to create your email.

For example:

post "/signup" do
  # sign up the user, and then:
  email :to      => @user.email, 
        :from    => "[email protected]", 
        :subject => "Welcome to Awesomeness!",
        :body    => haml(:some_template)
end

Usage

Classic top-level Sinatra style applications

require 'sinatra/mailer'

Modular Sinatra style applications

require 'sinatra/mailer'

class MyModularApp < Sinatra::Base
  register Sinatra::Mailer
end

Configuration

This plugin is very dirty yet :) Since it's just a port to Sinatra of Merb::Mailer. So the configuration is not Sinatra-y, yet. But we'll get to that.

Using SMTP

Sinatra::Mailer.config = {
  :host   => 'smtp.yourserver.com',
  :port   => '25',
  :user   => 'user',
  :pass   => 'pass',
  :auth   => :plain # :plain, :login, :cram_md5, the default is no auth
  :domain => "localhost.localdomain" # the HELO domain provided by the client to the server
}

Using Gmail SMTP

You need smtp-tls, a gem that improves net/smtp to add support for secure servers such as Gmail.

require "smtp-tls"

Sinatra::Mailer.config = {
  :host => 'smtp.gmail.com',
  :port => '587',
  :user => '[email protected]',
  :pass => 'pass',
  :auth => :plain
}

Make sure that when you call your email method you pass the :text option and not :body.

Using sendmail

Sinatra::Mailer.config = {:sendmail_path => '/somewhere/odd', :arguments => '-i -t'}
Sinatra::Mailer.delivery_method = :sendmail

Credits

This has been blatantly adapted from Merb::Mailer, so all credit is theirs, I just ported it to Sinatra.

About

Send emails from Sinatra in a very simple way (rewriting as Sinatra 0.9.1+ extension)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%