Skip to content

Instantly share code, notes, and snippets.

@rummelonp
Created January 26, 2012 16:00
Show Gist options
  • Save rummelonp/1683479 to your computer and use it in GitHub Desktop.
Save rummelonp/1683479 to your computer and use it in GitHub Desktop.
Sinatra でメール送信フォーム
# -*- coding: utf-8 -*-
require 'sinatra/base'
require 'haml'
require 'padrino-helpers'
require 'padrino-mailer'
class Mailer < Sinatra::Base
register Padrino::Helpers
register Padrino::Mailer
enable :inline_templates
set :haml, format: :html5
set :delivery_method, :smtp => {
address: 'smtp.gmail.com',
port: 587,
user_name: '<username>@gmail.com',
password: '<password>',
authentication: :plain,
enable_starttls_auto: true
}
get '/' do
haml :index
end
post '/send' do
email({
to: '<username>@gmail.com',
from: params[:from],
subject: params[:subject],
body: params[:body],
})
'Sent mail!'
end
end
__END__
@@layout
!!!
%title Mail
%meta{charset: 'utf-8'}
%body
%header
%h1 Mail
%section
= yield
@@index
- form_tag :send do
%p from:
%p= text_field_tag :from
%p subject:
%p= text_field_tag :subject
%p body:
%p= text_area_tag :body
%p= submit_tag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment