2014-07-23 47 views
0

很久以前,我设置了RoR4-Mailer。它工作正常。过了一段时间,我再也收不到电子邮件了。我不记得我如何设置它,所以我问谷歌。重置后,我收到一个错误,你可以在底部看到。邮件设置 - 基本配置

任何人都可以告诉我如何正确配置它吗? (我只想使用基本没有设计或任何其他宝石。)

我的代码片段:

/config/initializers/setup_mail.rb:

ActionMailer::Base.delivery_method = :smtp 
ActionMailer::Base.smtp_settings = { 
    address: "smtp.gmail.com", 
    port: "587", 
    domain: "gmail.com", 
    user_name: ENV["MAIL_USERNAME"], 
    password: ENV["MAIL_PASSWORD"], 
    authentication: "plain", 
    enable_starttls_auto: true, 
} 

/config/environments/development.rb:

# Don't care if the mailer can't send. 
    config.action_mailer.raise_delivery_errors = true 
    #default host-url 
    config.action_mailer.default_url_options = { :host => 'localhost:3000' } 

    config.action_mailer.delivery_method = :smtp 
    config.action_mailer.smtp_settings = { 
     :address => "smtp.gmail.com", 
     :port => 587, 
     :domain => ENV["GMAIL_DOMAIN"], 
     :authentication => "plain", 
     :enable_starttls_auto => true, 
     :user_name => ENV["GMAIL_USERNAME"], 
     :password => ENV["GMAIL_PASSWORD"] 
    } 

/local_env.yml:

GMAIL_DOMAIN: 'gmail.com' 
GMAIL_USERNAME: '[email protected]' 
GMAIL_PASSWORD: 'password' 

/config/application.rb:

config.before_configuration do 
    env_file = File.join(Rails.root, 'config', 'local_env.yml') 
    YAML.load(File.open(env_file)).each do |key, value| 
    ENV[key.to_s] = value 
    end if File.exists?(env_file) 
end 

错误的异常:

Net::SMTPAuthenticationError in AuthController#send_pwd_reset_instructions 
530-5.5.1 Authentication Required. 
+1

设置邮件为http://stackoverflow.com/questions/23300150/actionmailer-not-working-when-i-change-gmail -password/23300459#23300459 –

+0

尝试登录并确定帐户是否已被标记为可疑活动http://stackoverflow.com/questions/17227532/gmail-530-5-5-1-authentication-required-learn-more - 在 – dav1dhunt

+0

@ShamsulHaque: 如果我不使用ENV.Var它工作正常。谢谢。 但我会问谷歌如何正确使用ENV.Var。 – Ismoh

回答

0

看看ShamsulHaque评论:
“设置邮件为stackoverflow.com/questions/23300150/... - Shamsul Haque昨天”

+0

你应该投票,如果http://stackoverflow.com/questions/23300150/actionmailer-not-working-when-i-change-gmail-password/23300459#23300459帮助你。 –