From 4e7be83b8611611ec3b83ff49f1f519d6e009319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Sun, 15 Sep 2024 11:00:37 +0800 Subject: [PATCH] Fix mail verify. --- lib/tasks/e_paper_tasks.rake | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) 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}>")