邮件程序设置 - 基本配置

时间:2014-07-23 13:15:12

标签: ruby-on-rails ruby ruby-on-rails-4 mailer

我很久以前就设置了RoR4-Mailer。它工作正常。过了一会儿我再也没有收到电子邮件了。我无法记住我是如何设置它的,所以我问谷歌。重置后,我会在底部看到错误。

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

My Code-Snippets:

/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: 'username@gmail.com'
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 个答案:

答案 0 :(得分:0)

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