【问题标题】:Net::SMTPAuthenticationError网络::SMTPAuthenticationError
【发布时间】:2014-10-25 04:34:54
【问题描述】:

我正在尝试设置我的 rails 4 应用程序,以便它发送电子邮件。有谁知道我为什么会得到:

Net::SMTPAuthenticationError
534-5.7.9 Application-specific password required.

??????

我正在使用设计,并且刚刚设置了一个单独的“共享”邮件程序来发送电子邮件。我已经尝试按照对此类问题的其他回复中的建议访问accounts.google.com/b/0/DisplayUnlockCaptcha,但是当我重新启动服务器并尝试以用户身份发送电子邮件时,没有任何变化。

有什么想法吗?干杯!

config/environments/development.rb:

Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # In the development environment your application's code is reloaded on
  # every request. This slows down response time but is perfect for development
  # since you don't have to restart the web server when you make code changes.
  config.cache_classes = false

  # Do not eager load code on boot.
  config.eager_load = false

  # Show full error reports and disable caching.
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Don't care if the mailer can't send.
  # config.action_mailer.raise_delivery_errors = true

  config.action_mailer.delivery_method = :smtp

  # Gmail SMTP server setup
  ActionMailer::Base.smtp_settings = {
    :address => "smtp.gmail.com",
    :domain => "mail.google.com",
    :port => 587,
    :authentication => :plain,
    :user_name => "myrealaddress@gmail.com",
    :password => "myrealpassword",
    :enable_starttls_auto => true
  }

  # Print deprecation notices to the Rails logger.
  config.active_support.deprecation = :log

  # Raise an error on page load if there are pending migrations.
  config.active_record.migration_error = :page_load

  # Debug mode disables concatenation and preprocessing of assets.
  # This option may cause significant delays in view rendering with a large
  # number of complex assets.
  config.assets.debug = true

  # Adds additional error checking when serving assets at runtime.
  # Checks for improperly declared sprockets dependencies.
  # Raises helpful error messages.
  config.assets.raise_runtime_errors = true

  # Raises error for missing translations
  # config.action_view.raise_on_missing_translations = true
  config.action_mailer.default_url_options = { :host => 'localhost:3000' }

  # false prevents mail from being sent in development environment
  config.action_mailer.perform_deliveries = true
end

邮寄/分享:

class Share < ActionMailer::Base
    default_url_options[:host] = "localhost:3000"
  default from: "myrealaddress@gmail.com"

  def profile(profile, destination)
   @profile = profile
   mail(to: destination, subject: "sent you stuff")
  end
end

【问题讨论】:

  • 我认为你的 gmail 有问题,可能是被锁定了。尝试在 gmail 上使用该帐户登录,看看会发生什么。
  • 嗨!我可以正常登录。我也尝试解锁验证码,无论哪种方式都应该允许访问 10 分钟......仍然不知道为什么它不开心。任何想法如何禁用发送,以便我可以摆脱浏览器错误?
  • 尝试测试一个简单的发送电子邮件功能以确保它正常工作

标签: email ruby-on-rails-4 devise actionmailer


【解决方案1】:

错误是因为您的帐户启用了双重身份验证。要使用启用了双重身份验证的 gmail 帐户,您只需生成一个新的应用密码以用于您的邮件配置。

可以在此处生成新的 gmail 应用密码 - https://security.google.com/settings/security/apppasswords

在生成新密码时,为Select App 设置选择Mail,为Select Device 设置选择Other(Custom name)

一旦你有了新密码,用谷歌为你生成的随机字符串更新你的邮件配置,你应该被设置。

【讨论】:

  • 我不确定为什么 OP 没有将此响应标记为正确答案 - 这正是所要求的。随着越来越多的用户转向两步法,这个答案只会变得更加相关。
猜你喜欢
  • 2019-07-06
  • 2012-11-02
  • 2014-12-29
  • 2020-04-03
  • 2016-04-29
  • 2021-03-14
  • 2019-08-26
  • 2018-01-12
  • 2020-11-04
相关资源
最近更新 更多