我试图设置我的rails 4应用程序,以便发送电子邮件。有谁知道我为什么会这样做:
Net::SMTPAuthenticationError
534-5.7.9 Application-specific password required.
??????
我正在使用设计并且刚刚设置了一个单独的"分享"邮件发送邮件。我已尝试访问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
邮件收发器/股:
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
答案 0 :(得分:13)
错误是因为您的帐户启用了双因素身份验证。要使用启用了双因素身份验证的Gmail帐户,您只需生成一个新的应用密码即可用于邮件程序配置。
可以在此处生成gmail的新应用密码 - https://security.google.com/settings/security/apppasswords。
生成新密码时,请为Mail
设置选择Select App
,为Other(Custom name)
设置选择Select Device
。
获得新密码后,使用Google为您生成的随机字符串更新您的邮件程序配置,您应该设置。