Skip to content

Instantly share code, notes, and snippets.

@wavesummit
Created December 5, 2010 16:45
Show Gist options
  • Save wavesummit/729228 to your computer and use it in GitHub Desktop.
Save wavesummit/729228 to your computer and use it in GitHub Desktop.
An example sinatra app that uses pony and gmail to send an e-mail
.grid_12
%h1 Contact
%h2 Want to get in contact, have a question or just fancy a chat?
%p Fill out the form below
%form{:action => "/contact", :method => "post"}
%div{:style => "margin:0;padding:0;display:inline"}
%label{:for => "contact_subject"} Subject:
%br
%input#contact_subject{:name => "subject", :size => "30", :type => "text"}/
%br
%label{:for => "contact_email"} Email:
%br
%input#contact_email{:name => "email", :size => "30", :type => "text"}/
%br
%label{:for => "contact_message"} Message:
%br
%textarea#contact_message{:cols => "40", :name => "message", :rows => "3"}
%br
%input{:name => "commit", :type => "submit", :value => "Send"}/
%div{:style => "clear:both"}
require 'rubygems'
require 'sinatra/base'
require 'pony'
class Contact < Sinatra::Base
set :static, true
set :public, 'public'
get '/' do
return haml :contact
end
post '/' do
Pony.mail :to => ENV['TO_EMAIL'],
:from => params[:email],
:subject => params[:subject],
:body => params[:email] +" wrote:\n" + params[:message],
:via => :smtp,
:via_options => {
:address => 'smtp.gmail.com',
:port => '587',
:user_name => ENV['GMAIL_USER'],
:password => ENV['GMAIL_PASSWORD'],
:authentication => :plain,
:domain => "yourdomain.com"
}
return haml :contact_response
end
end
%h1 Your mail has been sent!
%p Thanks for getting in touch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment