mailer authentication error in Rails 3.2 with gmai

2019-07-02 10:45发布

I'm trying to set up mailing from a very simple Rails 3.2 app. Tried Gmail, tried SendGrid. Getting same error.

Net::SMTPAuthenticationError in UsersController#create
530-5.5.1 Authentication Required

Here's my section of environments/development.rb

# Care if the mailer can't send
config.action_mailer.raise_delivery_errors = true

# Change mail delivery to either :smtp, :sendmail, :file, :test
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address: "smtp.gmail.com",
  port: 587,
  domain: "signaldesign.net",
  authentication: "plain",
  enable_starttls_auto: true,
  user_name: ENV["gmailusername"],
  password: ENV["gmailpassword"]
}

Here's my users_controller

def create
  @user = User.new(params[:user])
  if @user.save
    UserMailer.signup_confirmation(@user).deliver
    sign_in @user
    flash[:success] = "Welcome!"
    redirect_to @user
  else
    render 'new'
  end
end

I'm stumped. None of the suggestions I've found online are making a difference.

3条回答
▲ chillily
2楼-- · 2019-07-02 11:13

Meanwhile the gem dotenv changed its implementation. You can now use your ENV settings to initialize the ActionMailer. I verified this with dotenv v.0.7.0. Make sure you load the environment variables. Autoloading has been removed from the gem. Read here.

查看更多
劳资没心,怎么记你
3楼-- · 2019-07-02 11:16

Try changing the domain to localhost.localdomain

查看更多
Juvenile、少年°
4楼-- · 2019-07-02 11:21

I figured it out. I finally resorted to just deleting things and trying again.

I changed my smtp_settings username and password from:

user_name: ENV["gmailusername"],
password: ENV["gmailpassword"]

to

user_name: "gmailusername",
password: "gmailpassword"
查看更多
登录 后发表回答