Rails devise with gmail errors

Viewed 6200

I'm currently working on an application with a mailer system. It was working fine, sending a welcome email and sending instructions to reset password, but now and only when I try to send reset instructions I have this error.

ArgumentError (SMTP From address may not be blank: nil):

I'm using a custom domain like so noreply@mycustomdomain.com And here is my configuration

development.rb

 config.action_mailer.raise_delivery_errors = true
 config.action_mailer.perform_caching = false
 config.action_mailer.default_url_options = { host: 'localhost:3000' }

 config.action_mailer.delivery_method = :smtp
 config.action_mailer.smtp_settings = {
     address: 'smtp.gmail.com',
     port: '587',
     domain: 'gmail.com',
     authentication: :plain,
     enable_starttls_auto: true,
     user_name: Rails.application.secrets.mailer_username,
     password: Rails.application.secrets.mailer_password
}

Any idea ?

Edit

class UserMailer < ApplicationMailer
  default from: 'noreply@mycustomdomain.com'

  def welcome_email(user)
    @user = user
    @url = 'http://localhost:3000/users/sign_in'
    mail(to: @user.email, subject: 'Bienvenue')
  end

  def generate_new_password_email
    user = User.find(params[:user_id])
    user.send_reset_password_instructions
  end

  def reset_password; end
end
5 Answers

You could try setting :from in your config, using the default_option like this,

config.action_mailer.default_options = { from: 'noreply@mycustomdomain.com' }

I stumbled upon the same problem. My solution was, I edited config/initializers/devise.rb changed a line from config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' to config.mailer_sender = ENV["default_from_email"]

Related