Skip to content

Instantly share code, notes, and snippets.

@flores
Created November 26, 2011 21:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save flores/1396337 to your computer and use it in GitHub Desktop.
Save flores/1396337 to your computer and use it in GitHub Desktop.
Sinatra + Sanitize + AWS SES Contact form, example
%form{ :action => "/", :method => "post"}
%label{:for => "name"} name:
%input{:type => "text", :name => "name""}
%label{:for => "mail"} email:
%input{:type => "text", :name => "mail"}
%label{:for => "subject"} subject:
%input{:type => "text", :name => "subject"}
%label{:for => "body"} message:
%textarea{:name => "body"}
%input{:type => "submit", :value => "send", :value => "send"}
#!/usr/bin/env ruby -r openssl
require 'rubygems'
require 'sinatra'
require 'haml'
require 'sanitize'
require 'aws/ses'
set :environment, :production
set :port, '4000'
set :bind, 'localhost'
get '/' do
haml :contact
end
post '/' do
name = Sanitize.clean(params[:name])
mail = Sanitize.clean(params[:mail])
subject = Sanitize.clean(params[:subject])
body = Sanitize.clean(params[:body])
ses = AWS::SES::Base.new(
:access_key_id => 'someid',
:secret_access_key => 'somekey'
)
# stick the user info into the subject instead of headers
ses.send_email(
:to => 'someemail',
:from => 'somefilteredemail',
:subject => mail + " - " + name + " - " + subject,
:body => body
)
haml :success
end
error do
haml :error
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment