Home > Blockchain >  NoMethodError (undefined method `timeout' for #<Net::SMTP smtp.gmail.com:587 started=false&g
NoMethodError (undefined method `timeout' for #<Net::SMTP smtp.gmail.com:587 started=false&g

Time:06-10

Rails 7 not recieving email from action mailer. it forms the email then i get an error 500 saying no method timeout for #<Net::SMTP smtp.gmail.com:587 started=false>

i have spent a few hours on this i have tried many different configurations, can someone guide me as to what i might be missing?

below i am using my gmail with an app password enabled. also i am using the devise gem to generate the email.

  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_caching = false
  config.action_mailer.default_url_options = { :host => 'localhost:3000', protocol: 
  'http' }
  
  ActionMailer::Base.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.default :charset => "utf-8"
  ActionMailer::Base.smtp_settings = {
    :address              => "smtp.gmail.com",
         :port                 => 587,
         :domain               => 'localhost:3000',
         :authentication       => :plain,
         :user_name            => '**********',
         :password             => '**********',
         :enable_starttls_auto => true,
}

CodePudding user response:

Your Gmail settings need to setup "Less secure app access", just as the rails guide mentioned:

On July 15, 2014, Google increased its security measures to block attempts from apps it deems less secure. You can change your Gmail settings here to allow the attempts. If your Gmail account has 2-factor authentication enabled, then you will need to set an app password and use that instead of your regular password.

Ref: https://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration-for-gmail

CodePudding user response:

Ok so the issue was that i had the tlsmail gem installed at some point. This gem replaces the smtp classes used for sending out emails. I removed the gem and i am good to go.

  • Related