diff --git a/lib/tasks/e_paper_tasks.rake b/lib/tasks/e_paper_tasks.rake index 30e95d7..f450c88 100644 --- a/lib/tasks/e_paper_tasks.rake +++ b/lib/tasks/e_paper_tasks.rake @@ -32,13 +32,20 @@ namespace :epaper do Thread.new do tmp = [] site = Site.first - @address = site['site_settings']['address'] - @port = (site['site_settings']['port'].to_i rescue 587) + if site[:gmail_login_flag] + @address = '127.0.0.1' + @port = 25 + tls = false + from_addr = site.gmail + else + @address = site['site_settings']['address'] + @port = (site['site_settings']['port'].to_i rescue 587) + tls = (site['site_settings']['enable_starttls_auto'] == "1") + from_addr = site['site_settings']['service_email'] + end @open_timeout = 10 @read_timeout = 60 @debug_output = nil - tls = (site['site_settings']['enable_starttls_auto'] == "1") - from_addr = site['site_settings']['service_email'] 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 @@ -49,7 +56,7 @@ namespace :epaper do puts "Emails will be sent at #{email_sentdate.strftime("%Y-%m-%d %H:%M")}" else email.deliver - puts "Sending #{deliver_emails.count} emails" + puts "Sending #{deliver_emails.count} emails: #{deliver_emails}" end rescue => e puts [deliver_emails.inspect,e,e.backtrace] @@ -72,8 +79,14 @@ namespace :epaper do end end def epaper_verify_email(from_addr,check_emails,tls) #true if check_email is ok - s = Timeout.timeout(@open_timeout, Net::OpenTimeout) do - TCPSocket.open(@address, @port) + return [] if @mail_server_broken + begin + s = Timeout.timeout(@open_timeout, Net::OpenTimeout) do + TCPSocket.open(@address, @port) + end + rescue => e + puts [e.to_s, e.backtrace] + @mail_server_broken = true end @socket = epaper_new_internet_message_io(tls ? epaper_tlsconnect(s) : s) res = epaper_get_response("MAIL FROM:<#{from_addr}>")