Created
October 2, 2011 22:22
-
-
Save kikito/1258047 to your computer and use it in GitHub Desktop.
Minimal sinatra contact us app
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 'app' | |
# application-exclusive settings | |
set :smtp_port, '587' | |
set :smtp_server, 'smtp.gmail.com' | |
set :smtp_password, 'secret' | |
set :smtp_user, 'my_mail@example.com' | |
set :address, 'my_mail@example.com' | |
set :domain, 'example.com' | |
# common sinatra settings | |
set :environment, ENV['RACK_ENV'].to_sym | |
set :app_file, 'app.rb' | |
disable :run | |
log = File.new("logs/sinatra.log", "a") | |
STDOUT.reopen(log) | |
STDERR.reopen(log) | |
run Sinatra::Application |
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
# Minimal sinatra web app | |
# This app should receive a request such as this one: | |
# | |
# http://yourserver.com/send-mail?subject=foo&name=bar&email=a@a.com&body=baz | |
# | |
# An email should be sent to the email address set up in the configuration | |
require 'rubygems' | |
require 'sinatra' | |
require 'pony' | |
get '/send-mail' do | |
subject = params[:subject] | |
name = params[:name] | |
email = params[:email] | |
body = params[:body] | |
Pony.mail( | |
:to => settings.address, | |
:subject => "[Contact]: #{subject}", | |
:body => "from: #{name} (#{email}) \n\n#{body}", | |
:via => :smtp, | |
:attachments => [], | |
:via_options => { | |
:address => settings.smtp_server, | |
:port => settings.smtp_port, | |
:enable_starttls_auto => true, | |
:user_name => settings.smtp_user, | |
:password => my_smtp_password, | |
:authentication => :plain, # :plain, :login, :cram_md5, no auth by default | |
:domain => settings.domain # the HELO domain provided by the client to the server | |
} | |
) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment