Commit b9a53535 by tady

mail, action_gmailer

parent 433142e4
...@@ -78,5 +78,7 @@ gem 'ancestry' ...@@ -78,5 +78,7 @@ gem 'ancestry'
# profiler # profiler
gem 'rack-mini-profiler' gem 'rack-mini-profiler'
# Google smtp # Send mail via gmail oauth
gem 'gmail_xoauth' # ref. https://github.com/popgiro/action-gmailer
gem 'mail'
gem 'action-gmailer', github: 'popgiro/action-gmailer'
GIT GIT
remote: git://github.com/popgiro/action-gmailer.git
revision: e04b69f578ead4514f6cea5ac85db16896f7e71c
specs:
action-gmailer (0.1.0)
actionmailer
activesupport
gmail_xoauth
GIT
remote: git://github.com/vmg/redcarpet.git remote: git://github.com/vmg/redcarpet.git
revision: 52c5fa3c5753d2125e827f235cdf4cb730484902 revision: 52c5fa3c5753d2125e827f235cdf4cb730484902
branch: master branch: master
...@@ -168,14 +177,15 @@ PLATFORMS ...@@ -168,14 +177,15 @@ PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
action-gmailer!
ancestry ancestry
better_errors better_errors
binding_of_caller binding_of_caller
coderay coderay
coffee-rails (~> 4.0.0) coffee-rails (~> 4.0.0)
devise devise
gmail_xoauth
jbuilder (~> 1.2) jbuilder (~> 1.2)
mail
omniauth-google-oauth2 omniauth-google-oauth2
pg pg
rack-mini-profiler rack-mini-profiler
......
require 'mail'
require 'action_gmailer'
module RV::Mailer
def self.compose_mail(subject, body, user)
mail = Mail.new do
from user.email
to user.email
subject subject
body body
end
# set ActionGmailer
config = {
oauth2_token: user.google_auth_token,
account: user.email
}.merge(Rendezvous::Application.config.action_mailer.smtp_settings)
mail.delivery_method(ActionGmailer::DeliveryMethod, config)
mail
end
end
require 'nkf' require 'nkf'
require 'rv/mailer'
class PostsController < ApplicationController class PostsController < ApplicationController
...@@ -53,23 +54,10 @@ class PostsController < ApplicationController ...@@ -53,23 +54,10 @@ class PostsController < ApplicationController
def mail def mail
@post = set_post @post = set_post
smtp = Net::SMTP.new('smtp.gmail.com', 587)
smtp.enable_starttls_auto subject = @post.title
smtp.start('smtp.gmail.com', current_user.email, current_user.google_auth_token, :xoauth2) body = @post.body
body = 'test' RV::Mailer.compose_mail(subject, body, current_user).deliver
body2 = <<EOT
From: #{current_user.email}
To: #{current_user.email}
Subject: #{NKF.nkf("-WjMm0", 'subject')}
Date: #{Time::now.strftime("%a, %d %b %Y %X %z")}
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-2022-JP
Content-Transfer-Encoding: 7bit
#{NKF.nkf("-Wjm0", body)}
EOT
smtp.send_mail(body2, current_user.email, current_user.email)
smtp.finish
redirect_to root_path(id: @post.id) redirect_to root_path(id: @post.id)
end end
...@@ -142,4 +130,5 @@ EOT ...@@ -142,4 +130,5 @@ EOT
_param_hash _param_hash
end end
end end
end end
...@@ -21,5 +21,18 @@ module Rendezvous ...@@ -21,5 +21,18 @@ module Rendezvous
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de # config.i18n.default_locale = :de
# config.action_mailer.delivery_method = :action_gmailer
config.action_mailer.smtp_settings = {
smtp_host: 'smtp.gmail.com',
smtp_port: 587,
helo_domain: 'gmail.com',
auth_type: :xoauth2,
# oauth2_token: 'FIXME',
# account: 'FIXME'
}
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment