1

我正在开发一个 webscraper,它将每周发送一个包含 Ruby 新内容的 CSV。对于邮件组件,我决定使用Mail gem。经过大量的修补后,我得到了它来发送一些测试电子邮件。但是,我经常收到此错误:

...smtp.rb:541:in `initialize': execution expired (Net::OpenTimeout)...

我有一个合理的互联网连接,并且无法检测到任何类型的错误模式。这是我的邮件代码:

require 'mail'

def sendEmail(newEventCount, newEventArray)

    if newEventArray.to_a.empty? == true
        emailBodyText = "No new events were added this week."
    else
        newEventString = "The new events are: "
        newEventArray.each do |event|
            newEventString = newEventString + event + "\n"
        end
        emailBodyText = "#{newEventCount} events were added this week. #{newEventString}"
    end 

    options = { :address => "smtp.gmail.com",
                :port => 587,
                :domain => '(my public ip address according to google)',
                :user_name => '(my username)',
                :password => '(my password)',
                :authentication => 'plain',
                :enable_starttls_auto => true }

    Mail.defaults do 
        delivery_method :smtp, options
    end

    mail = Mail.new do 
        from '(my email)'
        to '(recipient email)'
        subject 'Weekly Scrape Results'
        body emailBodyText

        add_file './events.csv'
    end

    mail.deliver!
end
4

0 回答 0