2017-09-28 51 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

您必须在谷歌中启用安全性较低的应用。我已经尝试使用环境变量以外的原始凭据,但仍然无法正常工作。 –

相关问题