2017-09-28 56 views
0

我每次嘗試通過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 } 

回答

1

該配置似乎是正確的。你可以嘗試刪除域名?如果您想使用域名,請使用'gmail.com'而不是mail.google.com。以下是我的配置。請注意,我使用了config.action_mailer.smtp_settings = {而不是ActionMailer::Base.smtp_settings = {。我不確定這是否會成爲問題。

config.action_mailer.raise_delivery_errors = true 

    config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } 

    config.action_mailer.perform_deliveries = true 

    config.action_mailer.default_options = {from: '[email protected]'} 

    # Mail settings 
    config.action_mailer.delivery_method = :smtp 

    # SMTP settings for gmail 
    config.action_mailer.smtp_settings = { 
    :address    => "smtp.gmail.com", 
    :port     => 587, 
    :user_name   => '[email protected]', 
    :password    => 'password', 
    :authentication  => "plain", 
    :enable_starttls_auto => true 
    } 

    config.action_mailer.asset_host = 'http://localhost:3000' 

編輯

賈斯汀說,您必須啓用nable在谷歌不夠安全的應用。底部可以是here。像下面的圖片

enter image description here

我面臨的另一個問題,而從生產環境中發送郵件。 This幫我找出了另一件需要照顧的事情。顯然你需要提供對應用程序的訪問。你可以從here。只需點擊繼續並等待10分鐘即可完成更改。

你很高興在這之後發送生產電子郵件。

*側面說明:我所面臨的問題上面,當我在Heroku的*

+0

嘿部署的應用程序,只是想你的建議,但仍然沒有成功。我認爲問題是谷歌ACC設置(糾正我,如果我錯了),我只是不知道如何去做。謝謝您的好意。 –

+0

據我所知,我們無需進行任何Google設置。你確定你使用的是正確的憑證。也許嘗試直接替換用戶名和密碼,而不使用環境變量。如果是這個問題? – Aakanksha

+0

您必須在谷歌中啓用安全性較低的應用。我已經嘗試使用環境變量以外的原始憑據,但仍然無法正常工作。 –

相關問題