Rails ActionMailer intermittently working with smtp-relay.gmail.com

Viewed 189

I'm getting an error with a GMail account using an SMTP Relay configuration. For some odd reason though, only 40-50% actually get sent, and the rest error out. I'm using Rails' v6.0.3.2 ActionMailer with DelayedJobs gem v4.1.8.

Error

EOFError: end of file reached

SMTP configuration:

config.action_mailer.smtp_settings = {
  address: 'smtp-relay.gmail.com',
  port: 587,
  enable_starttls_auto: true
}

And this is the code I'm using to send the emails:

class ApplicationMailer < ActionMailer::Base
  default from: 'email@email.es'
  layout 'mailer'
  def test
    mail(to: 'to@email.es', subject: 'Subject')
  end
end

I've made some tests outside of the Rails project and the same error happens:

require 'net/smtp'
Net::SMTP.start('smtp-relay.gmail.com', 587) do |smtp|
  smtp.enable_starttls
  smtp.send_message 'Hello world!', 'email@email.es', 'to@email.es'
end
1 Answers

Syntax errors

class ApplicationMailer < ActionMailer::Base
  default from: 'email@email.es' # the first single quote position is wrong
  layout 'mailer'

  def test
    # to: ... requires to be a string
    mail(to: 'to@email.es', subject: 'Subject') # Closing quote on 'Subject missing' 
  end
end
Related