$ vi lib/tasks/notify.rake
def notify_rating(mails,un_rates) body = %Q{ ==本郵件由系統發送,請勿直接回覆。== 敬愛的用戶﹕ 您好﹗ 您於#{un_rates[:train_date]}參加了#{un_rates[:uname]}主講的課程: 【 #{un_rates[:cname]}】。 目前您尚未對該課程進行滿意度評價, 為避免此提醒Mail對您的再次打擾, 煩請登入以下網址進行評分: http://172.18.60.39:3000/main/train_app#train_regist_de_des 以上如有任何問題請提出, 謝謝! } Pony.mail( :to => mails, :from => 'IT Train<[email protected]>', :cc => 'Jamie Kao<[email protected]>,YSR<[email protected]>,WHZ<[email protected]>', :subject => '[IT教育訓練問卷調查網站 ] 通知', :charset => 'utf-8', :body => body, :via => :smtp, :via_options => { :address => 'email.pyzs.com.cn', :port => 25, :enable_starttls_auto => true, :user_name => 'username', :password => 'password', :authentication => :login, :domain => "localhost.localdomain" # the HELO domain provided by the client to the server }) end namespace :notify do desc "Notify rating" task :rating do db = Sequel.connect('oracle://mis:[email protected]:1521/test') sql = "select distinct train_regist_id, train_date, uname, cname from vie_un_rates where train_date between to_date('20110616','yyyymmdd') and sysdate" db[sql].each do |row| #puts row[:cname] un_rates = row mails = [] db[:vie_un_rates].where(:train_regist_id => row[:train_regist_id]).each do |row| #puts "Notify #{row[:name]}#{row[:email]}" mails << "'#{row[:name]}' <#{row[:email]}>" end notify_rating(mails,un_rates) end end end
$rake notify:rating
注意:
ruby1.9+rails3環境下會出現異常:invalid multibyte char (US-ASCII)
解决办法是在文件的第一行加上:
# encoding: utf-8