【问题标题】:mailer authentication error in Rails 3.2 with gmail or SendGridRails 3.2 中使用 gmail 或 SendGrid 的邮件验证错误
【发布时间】:2012-07-03 09:53:18
【问题描述】:

我正在尝试从一个非常简单的 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

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

【问题讨论】:

  • 您是否尝试过硬编码用户名和密码?
  • 我不确定你的意思。当我在本地主机上进行测试时,我将它们放在该配置文件中。刚刚为这篇文章更改了它们。

标签: ruby-on-rails smtp gmail actionmailer


【解决方案1】:

尝试将域更改为localhost.localdomain

【讨论】:

  • 不。这并没有改变任何东西。
【解决方案2】:

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

我将我的 smtp_settings 用户名和密码更改为:

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

user_name: "gmailusername",
password: "gmailpassword"

【讨论】:

  • 听起来您从未在服务器上设置环境变量。如果您使用的是 heroku,他们会在您添加插件后为您添加 SendGrid
  • @swift 是的,我终于明白了。我决定,现在,继续尝试让 gmail 工作。我在 heroku 配置中有环境变量,但是当 actionmailer 拨打电话时,我无法让 heroku 使用它们。我需要制作一个初始化程序,但我无法将它们全部连接在一起。有什么建议吗?
  • 如果您运行heroku config,您会看到您的凭据吗?
【解决方案3】:

与此同时,gem dotenv 改变了它的实现。您现在可以使用您的ENV 设置来初始化ActionMailer。我用dotenv v.0.7.0 验证了这一点。确保加载环境变量。自动加载已从 gem 中删除。阅读here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-27
    • 1970-01-01
    • 2013-02-06
    • 2013-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-20
    相关资源
    最近更新 更多