Skip to content

Instantly share code, notes, and snippets.

@abepetrillo
Forked from acwright/gist:1944639
Created March 28, 2014 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abepetrillo/9822505 to your computer and use it in GitHub Desktop.
Save abepetrillo/9822505 to your computer and use it in GitHub Desktop.
require 'sinatra'
require 'action_mailer'
class Mailer < ActionMailer::Base
def contact
mail(
:to => "test@example.com",
:from => "test@example.com",
:subject => "Test") do |format|
format.text
format.html
end
end
end
configure do
set :root, File.dirname(__FILE__)
set :views, File.join(Sinatra::Application.root, 'views')
set :haml, { :format => :html5 }
if production?
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => '25',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => ENV['SENDGRID_DOMAIN'],
}
ActionMailer::Base.view_paths = File.join(Sinatra::Application.root, 'views')
else
ActionMailer::Base.delivery_method = :file
ActionMailer::Base.file_settings = { :location => File.join(Sinatra::Application.root, 'tmp/emails') }
ActionMailer::Base.view_paths = File.join(Sinatra::Application.root, 'views')
end
end
post '/mail' do
email = Mailer.contact
email.deliver
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment