网:: SMTPAuthenticationError

sss*_*333 1 email actionmailer devise ruby-on-rails-4

我正在尝试设置我的rails 4 app,以便发送电子邮件.有谁知道我为什么得到:

Net::SMTPAuthenticationError
534-5.7.9 Application-specific password required.
Run Code Online (Sandbox Code Playgroud)

??????

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

有任何想法吗?干杯!

配置/环境/ 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
Run Code Online (Sandbox Code Playgroud)

邮件/共享:

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
Run Code Online (Sandbox Code Playgroud)

mik*_*ael 16

该错误是因为您的帐户启用了双因素身份验证.使用启用了双因素身份验证的Gmail帐户所需要做的就是生成一个新的应用密码,以便与您的邮件程序配置一起使用.

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

当生成一个新的密码选择Mail的Select App设置和Other(Custom name)对Select Device设置.

获得新密码后,使用Google为您生成的随机字符串更新您的邮件程序配置,您应该进行设置.

  • 我不确定为什么OP没有将此响应标记为正确的答案 - 这正是所要求的.随着越来越多的用户转向两步,这个答案将变得更加相关. (3认同)