2014-07-23 109 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幫助你。 –