-
-
Save EvertonSilva/7fa76c61b988b6eabf6c20868fb93d1f to your computer and use it in GitHub Desktop.
An example sinatra app that uses pony and gmail to send an e-mail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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