Commit b9a53535 by tady

mail, action_gmailer

parent 433142e4
......@@ -78,5 +78,7 @@ gem 'ancestry'
# profiler
gem 'rack-mini-profiler'
# Google smtp
gem 'gmail_xoauth'
# Send mail via gmail oauth
# ref. https://github.com/popgiro/action-gmailer
gem 'mail'
gem 'action-gmailer', github: 'popgiro/action-gmailer'
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
revision: 52c5fa3c5753d2125e827f235cdf4cb730484902
branch: master
......@@ -168,14 +177,15 @@ PLATFORMS
ruby
DEPENDENCIES
action-gmailer!
ancestry
better_errors
binding_of_caller
coderay
coffee-rails (~> 4.0.0)
devise
gmail_xoauth
jbuilder (~> 1.2)
mail
omniauth-google-oauth2
pg
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 'rv/mailer'
class PostsController < ApplicationController
......@@ -53,23 +54,10 @@ class PostsController < ApplicationController
def mail
@post = set_post
smtp = Net::SMTP.new('smtp.gmail.com', 587)
smtp.enable_starttls_auto
smtp.start('smtp.gmail.com', current_user.email, current_user.google_auth_token, :xoauth2)
body = 'test'
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
subject = @post.title
body = @post.body
RV::Mailer.compose_mail(subject, body, current_user).deliver
redirect_to root_path(id: @post.id)
end
......@@ -142,4 +130,5 @@ EOT
_param_hash
end
end
end
......@@ -21,5 +21,18 @@ module Rendezvous
# 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.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
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