问题
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.
回答1:
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"
回答2:
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:
Try changing the domain to localhost.localdomain
来源:https://stackoverflow.com/questions/11302900/mailer-authentication-error-in-rails-3-2-with-gmail-or-sendgrid