Add email_sentdate setting.
This commit is contained in:
parent
845ce926f3
commit
59b23772c3
|
@ -60,7 +60,13 @@ def initialize
|
|||
# rake = Rake::Task['epaper:send_email'].invoke([params[:id], request.host_with_port])
|
||||
paper = PaperCriteria.find(params[:id]) rescue nil
|
||||
if !paper.nil? && paper.invalid_emails.blank?
|
||||
render :json => {"success" => true}.to_json
|
||||
email_sentdate = paper.get_email_sentdate
|
||||
if paper.get_email_sentdate
|
||||
msg = I18n.t('e_paper.newsletter_will_be_sent', {time: email_sentdate.strftime("%Y-%m-%d %H:%M")})
|
||||
else
|
||||
msg = I18n.t('e_paper.newsletter_sent')
|
||||
end
|
||||
render :json => {"success" => true, "msg": msg}.to_json
|
||||
else
|
||||
invalid_email_list = paper.invalid_emails rescue 'can not find paper'
|
||||
render :json => {"success" => false,"invalid_emails"=>invalid_email_list}.to_json
|
||||
|
|
|
@ -16,6 +16,7 @@ class PaperCriteria
|
|||
field :other_emails
|
||||
field :invalid_emails, type: Array, :default => []
|
||||
field :send_failed_emails, type: Array, :default => []
|
||||
field :email_sentdate, :type => DateTime
|
||||
|
||||
mount_uploader :image, ImageUploader
|
||||
|
||||
|
@ -32,5 +33,13 @@ class PaperCriteria
|
|||
return []
|
||||
end
|
||||
end
|
||||
|
||||
def get_email_sentdate
|
||||
_email_sentdate = self.email_sentdate
|
||||
if _email_sentdate && _email_sentdate < DateTime.now
|
||||
_email_sentdate = nil
|
||||
end
|
||||
_email_sentdate
|
||||
end
|
||||
|
||||
end
|
|
@ -96,6 +96,14 @@
|
|||
<div class="hint">Separated by , (comma)</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content-box">
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t("e_paper.email_sentdate") %></label>
|
||||
<div class="controls">
|
||||
<%= f.datetime_picker :email_sentdate, :no_label => true, :new_record => @paper_criteria.new_record? %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="record">
|
||||
</div>
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
type : "get",
|
||||
success: function(data){
|
||||
if (data.success){
|
||||
alert("Newsletter sent.")
|
||||
alert(data.msg)
|
||||
}else{
|
||||
var window_width = window.innerWidth
|
||||
var window_height = window.innerHeight
|
||||
|
|
|
@ -51,3 +51,6 @@ en:
|
|||
receivers: Receivers
|
||||
send_newsletter: Send Newsletter
|
||||
language_to_send: "Languages allow be subscribed"
|
||||
email_sentdate: Email Time
|
||||
newsletter_sent: "Newsletter sent."
|
||||
newsletter_will_be_sent: "Newsletter will be sent at %{time}."
|
||||
|
|
|
@ -52,3 +52,6 @@ zh_tw:
|
|||
receivers: 收件人
|
||||
send_newsletter: 發送時事通訊
|
||||
language_to_send: 開放訂閱語系
|
||||
email_sentdate: 寄送時間
|
||||
newsletter_sent: "電子報已寄送!"
|
||||
newsletter_will_be_sent: "電子報會於%{time}寄送!"
|
|
@ -11,6 +11,7 @@ namespace :epaper do
|
|||
papers_data = Admin::EpaperHelper.get_paper_data(paper)
|
||||
domain = args[:domain]
|
||||
if !paper.nil?
|
||||
email_sentdate = paper.get_email_sentdate
|
||||
email_format = /^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+$/
|
||||
subscribers = EPaperSubscriber.where(:language.in=>paper.language_to_send,:email.nin=>['',nil],:subscribed.ne=>false)
|
||||
subscribers.update_all(:last_paper_sent => paper.id.to_s)
|
||||
|
@ -41,11 +42,15 @@ namespace :epaper do
|
|||
emails_valid.each_slice(mail_limit).each do |slice_emails|
|
||||
invalid_mails = epaper_verify_email(from_addr,slice_emails,tls)
|
||||
deliver_emails = slice_emails - invalid_mails
|
||||
email = Email.new(:mail_subject => paper.sending_title, :mail_lang => args[:locale], :template => "admin/e_paper_criterias/emailer", :template_data => {"paper_id" => paper.id, "page" => "http://" + domain + page, "siteurl" => "http://" + domain, "papers_data" => papers_data }, :mail_to => deliver_emails, :module_app_key=>'e_paper')
|
||||
email = Email.new(:mail_subject => paper.sending_title, :mail_lang => args[:locale], :template => "admin/e_paper_criterias/emailer", :template_data => {"paper_id" => paper.id, "page" => "http://" + domain + page, "siteurl" => "http://" + domain, "papers_data" => papers_data }, :mail_to => deliver_emails, :module_app_key=>'e_paper', :mail_sentdate=> email_sentdate)
|
||||
begin
|
||||
email.save
|
||||
email.deliver
|
||||
puts "Sending #{deliver_emails.count} emails"
|
||||
if email_sentdate
|
||||
puts "Emails will be sent at #{email_sentdate.strftime("%Y-%m-%d %H:%M")}"
|
||||
else
|
||||
email.deliver
|
||||
puts "Sending #{deliver_emails.count} emails"
|
||||
end
|
||||
rescue => e
|
||||
puts [deliver_emails.inspect,e,e.backtrace]
|
||||
tmp += deliver_emails
|
||||
|
@ -53,7 +58,7 @@ namespace :epaper do
|
|||
error_flag = 0
|
||||
begin
|
||||
invalid_mails.each do |invalid_mail|
|
||||
email = Email.create(:mail_subject => paper.sending_title, :mail_lang => args[:locale], :template => "admin/e_paper_criterias/emailer", :template_data => {"paper_id" => paper.id, "page" => "http://" + domain + page, "siteurl" => "http://" + domain, "papers_data" => papers_data }, :mail_to => invalid_mail, :module_app_key=>'e_paper')
|
||||
email = Email.create(:mail_subject => paper.sending_title, :mail_lang => args[:locale], :template => "admin/e_paper_criterias/emailer", :template_data => {"paper_id" => paper.id, "page" => "http://" + domain + page, "siteurl" => "http://" + domain, "papers_data" => papers_data }, :mail_to => invalid_mail, :module_app_key=>'e_paper', :mail_sentdate=> email_sentdate)
|
||||
end
|
||||
rescue => e
|
||||
puts [e,e.backtrace]
|
||||
|
|
Loading…
Reference in New Issue