我每次嘗試通過rails'localhost'或'c9'發送電子郵件時,都會遇到鏈接中顯示的錯誤。我在Google帳戶上啓用了「安全性較低的應用」,並嘗試了所有指南,但錯誤仍然相同。尋求幫助的人。 error snapshotAction Mailer Returning SMTPAuthentcationError
源文件是如下: suggestion_mailer.rb
class SuggestionMailer < ApplicationMailer
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.suggestion_mailer.new_suggestion.subject
#
def new_suggestion()
#@suggestion = suggestion
mail(:from => "[email protected]",
:to => "yyyyyyyyyyyyyygmail.com",
:subject => 'Thanks for signing up for our amazing app'
)
end
end
suggestion_controller.rb
def create
@suggestion = Suggestion.new(suggestion_params)
respond_to do |format|
if @suggestion.save
SuggestionMailer.new_suggestion().deliver
format.html { redirect_to suggestions_url, notice: 'Suggestion was
successfully created.' }
format.json { render :show, status: :created, location:
@suggestion }
else
format.html { render :new }
format.json { render json: @suggestion.errors, status:
:unprocessable_entity }
end
end
端
development.rb
config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:domain => "mail.google.com",
:port => 587,
:user_name => ENV['GMAIL_USERNAME'],
:password => ENV['GMAIL_PASSWORD'],
:authentication => "plain",
:enable_starttls_auto => true
#:openssl_verify_mode => 'none'
}
config.action_mailer.default_url_options = { host: 'localhost',
port: 3000 }
嘿部署的應用程序,只是想你的建議,但仍然沒有成功。我認爲問題是谷歌ACC設置(糾正我,如果我錯了),我只是不知道如何去做。謝謝您的好意。 –
據我所知,我們無需進行任何Google設置。你確定你使用的是正確的憑證。也許嘗試直接替換用戶名和密碼,而不使用環境變量。如果是這個問題? – Aakanksha
您必須在谷歌中啓用安全性較低的應用。我已經嘗試使用環境變量以外的原始憑據,但仍然無法正常工作。 –