Ruby on rails 如何使用gmail smtp服务发送确认电子邮件,以便在本地开发模式下使用Desive进行注册?
我有一个应用程序,它使用Desive为新注册的用户发送确认邮件,我在development.rb文件下有smtp设置,如下所示Ruby on rails 如何使用gmail smtp服务发送确认电子邮件,以便在本地开发模式下使用Desive进行注册?,ruby-on-rails,ruby-on-rails-3.1,devise,Ruby On Rails,Ruby On Rails 3.1,Devise,我有一个应用程序,它使用Desive为新注册的用户发送确认邮件,我在development.rb文件下有smtp设置,如下所示 config.action_mailer.default_url_options = { :host => 'http://localhost:3000' } config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => 'http://localhost:3000' }
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:authentication => :login,
:user_name => "my_username@gmail.com",
:password => "mygmail password"
}
这让我犯了一个错误,比如
Net::SMTPAuthenticationError in Devise::RegistrationsController#create
535-5.7.1 Please log in with your web browser and then try again. Learn more at
有没有办法解决这个问题
使用这些设置解决问题
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.perform_deliveries = true
config.action_mailer.default :charset => "utf-8"
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => "my_username@gmail.com",
:password => 'my_gmail password',
:authentication => "plain",
:enable_starttls_auto => true
}
:authentication=>“plain”我无法用任何代码解决此问题。过了一会儿,我登录到gmail帐户,这就是它给我的
We've detected suspicious activity on your Google Account. Please create a new password to continue using your account.
Read some tips on creating a secure password.
所以,解决这个问题的方法就是登录您用于发送电子邮件的帐户,并重新确认您的新密码
config.action_mailer.default_url_options = {:host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
# change to false to prevent email from being sent during development
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "example.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: "your_mail@gmail.com",
password: "your_password"
}
在创建了development.rb文件之后,如果您有问题,请登录到development.rb文件中使用的gmail帐户。
然后问题就解决了 您还可以删除:DomainOptionGoogle阻止发送电子邮件,因为它在我尝试从应用程序登录时检测到一些可疑活动。我的gmail帐户要求密码更改。我更改了密码,现在可以使用了。谢谢。最有趣的是,错误信息直接指向了那个方向。)