3

我正在尝试从一个非常简单的 Rails 3.2 应用程序设置邮件。尝试过 Gmail,尝试过 SendGrid。得到同样的错误。

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

这是我的环境/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"]
}

这是我的 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

我难住了。我在网上找到的任何建议都没有任何作用。

4

3 回答 3

4

我想到了。我最终只好删除一些东西然后再试一次。

我从以下位置更改了我的 smtp_settings 用户名和密码:

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

user_name: "gmailusername",
password: "gmailpassword"
于 2012-07-03T14:55:32.283 回答
1

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.

于 2013-04-23T13:41:59.767 回答
0

尝试将域更改为localhost.localdomain

于 2012-07-03T01:05:55.593 回答