# HG changeset patch # User Jittat Fakcharoenphol # Date 2012-10-03 17:58:32 # Node ID 4917c2675f37fb34c812d684499390537f33fb66 # Parent 82d41889f7a08854a930afde3d83a3f6f9d50e5f sends mails by mail gem diff --git a/Gemfile b/Gemfile --- a/Gemfile +++ b/Gemfile @@ -37,7 +37,7 @@ # gem 'debugger' gem "haml" -gem "tmail" +gem "mail" gem "rdiscount" gem "test-unit" gem 'will_paginate', '~> 3.0.0' diff --git a/Gemfile.lock b/Gemfile.lock --- a/Gemfile.lock +++ b/Gemfile.lock @@ -117,7 +117,6 @@ test-unit (2.5.2) thor (0.16.0) tilt (1.3.3) - tmail (1.2.7.1) treetop (1.4.10) polyglot polyglot (>= 0.3.1) @@ -135,6 +134,7 @@ dynamic_form haml in_place_editing + mail mysql2 prototype-rails rails (= 3.2.8) @@ -142,7 +142,6 @@ rspec-rails (~> 2.0) sass-rails (~> 3.2.3) test-unit - tmail uglifier (>= 1.0.3) verification! will_paginate (~> 3.0.0) diff --git a/app/controllers/user_admin_controller.rb b/app/controllers/user_admin_controller.rb --- a/app/controllers/user_admin_controller.rb +++ b/app/controllers/user_admin_controller.rb @@ -1,7 +1,5 @@ class UserAdminController < ApplicationController - #include MailHelperMethods - before_filter :admin_authorization # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) @@ -316,24 +314,31 @@ redirect_to :action => 'mass_mailing' and return end - subject = params[:subject] - if !subject or subject.blank? + mail_subject = params[:subject] + if !mail_subject or mail_subject.blank? flash[:notice] = 'You entered an empty mail subject.' redirect_to :action => 'mass_mailing' and return end + + mail_body = params[:email_body] + if !mail_body or mail_body.blank? + flash[:notice] = 'You entered an empty mail body.' + redirect_to :action => 'mass_mailing' and return + end - body = params[:email_body] - if !body or body.blank? - flash[:notice] = 'You entered an empty mail body.' - redirect_to :action => 'mass_mailing' and return - end + admin_email = GraderConfiguration['system.admin_email'] note = [] users = [] lines.split("\n").each do |line| user = User.find_by_login(line.chomp) if user - send_mail(user.email, subject, body) + Mail.deliver do + from admin_email + to user.email + subject mail_subject + body mail_body + end note << user.login end end @@ -426,17 +431,24 @@ def send_contest_update_notification_email(user, contest) contest_title_name = GraderConfiguration['contest.name'] contest_name = contest.name - subject = t('contest.notification.email_subject', { - :contest_title_name => contest_title_name, - :contest_name => contest_name }) - body = t('contest.notification.email_body', { - :full_name => user.full_name, - :contest_title_name => contest_title_name, - :contest_name => contest.name, - }) + mail_subject = t('contest.notification.email_subject', { + :contest_title_name => contest_title_name, + :contest_name => contest_name }) + mail_body = t('contest.notification.email_body', { + :full_name => user.full_name, + :contest_title_name => contest_title_name, + :contest_name => contest.name, + }) - logger.info body - send_mail(user.email, subject, body) + admin_email = GraderConfiguration['system.admin_email'] + + logger.info mail_body + Mail.deliver do + from admin_email + to user.email + subject mail_subject + body mail_body + end end def find_contest_and_user_from_contest_id(id) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,10 +1,7 @@ -require 'tmail' require 'net/smtp' class UsersController < ApplicationController - #include MailHelperMethods - before_filter :authenticate, :except => [:new, :register, :confirm, @@ -124,35 +121,46 @@ :login => user.login, :activation => user.activation_key) home_url = url_for(:controller => 'main', :action => 'index') - subject = "[#{contest_name}] Confirmation" - body = t('registration.email_body', { - :full_name => user.full_name, - :contest_name => contest_name, - :login => user.login, - :password => user.password, - :activation_url => activation_url, - :admin_email => admin_email - }) + mail_subject = "[#{contest_name}] Confirmation" + mail_body = t('registration.email_body', { + :full_name => user.full_name, + :contest_name => contest_name, + :login => user.login, + :password => user.password, + :activation_url => activation_url, + :admin_email => admin_email + }) - logger.info body + logger.info mail_body - send_mail(user.email, subject, body) + Mail.deliver do + from admin_email + to user.email + subject mail_subject + body mail_body + end end def send_new_password_email(user) contest_name = GraderConfiguration['contest.name'] admin_email = GraderConfiguration['system.admin_email'] - subject = "[#{contest_name}] Password recovery" - body = t('registration.password_retrieval.email_body', { - :full_name => user.full_name, - :contest_name => contest_name, - :login => user.login, - :password => user.password, - :admin_email => admin_email - }) + mail_subject = "[#{contest_name}] Password recovery" + mail_body = t('registration.password_retrieval.email_body', { + :full_name => user.full_name, + :contest_name => contest_name, + :login => user.login, + :password => user.password, + :admin_email => admin_email + }) - logger.info body - send_mail(user.email, subject, body) + logger.info mail_body + + Mail.deliver do + from admin_email + to user.email + subject mail_subject + body mail_body + end end end