1

I'm working on a webscraper that will send out a weekly CSV with new content with Ruby. For the mailing component I decided to use the Mail gem. After a great deal of tinkering I got it to send a few test emails. However, I frequently get this error:

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

I have a reasonable internet connection and haven't been able to detect any sort of pattern with the error. Here is my code for the mailer:

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
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Nicholas S
  • 25
  • 6

0 Answers0