我正在尝试使用非常简单的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
我很难过。我在网上找到的所有建议都没有带来任何影响。
答案 0 :(得分:4)
我明白了。我最终只是删除了一些内容并再次尝试。
我从:
更改了我的smtp_settings用户名和密码user_name: ENV["gmailusername"],
password: ENV["gmailpassword"]
到
user_name: "gmailusername",
password: "gmailpassword"
答案 1 :(得分:1)
同时gem dotenv改变了它的实施。您现在可以使用ENV
设置初始化ActionMailer
。我用dotenv v.0.7.0
验证了这一点。确保加载环境变量。自动加载已从gem中删除。阅读here。
答案 2 :(得分:0)
尝试将域名更改为localhost.localdomain