ruby-on-rails-4 - Net::SMTPAuthenticationError,535-5.7.8 用户名和密码不被接受

标签 ruby-on-rails-4 gmail actionmailer

我已经查看了此问题的先前答案,但我仍然无法弄清楚我的参数出了什么问题。

我修改了我的 Gmail 帐户,使其允许安全性较低的应用程序,并使用验证码将其解锁,但它仍然不接受我的用户名和密码,即使我确信它们是正确的。

这是我的文件:

配置/环境/生产.rb

config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
  config.action_mailer.smtp_settings = {
      :address              => "smtp.gmail.com",
      :port                 => 587,
      :user_name            => "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="264b5f4b474f4a66414b474f4a0845494b" rel="noreferrer noopener nofollow">[email protected]</a>",
      :password             => "mypassword",
      :authentication       => :login,
      :enable_starttls_auto => true
  }

config/initializers/smtp_settings.rb

ActionMailer::Base.smtp_settings = {
    :address => "smtp.gmail.com",
    :port => 587,
    :domain => "mywebsite.fr",
    :user_name => "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0a67736f676b63664a6d676b636624696567" rel="noreferrer noopener nofollow">[email protected]</a>",
    :password => 'myPassword',
    :authentication => :login,
    :enable_starttls_auto => true
}

我想我做错了什么,或者把一些东西放在不属于的地方。在看到这么多不同的方法后,我迷失了。

最佳答案

我是初学者,这是我第一次在 stackoverflow 上发帖,希望这对您有所帮助。如果我可以进一步帮助您,请告诉我!另外,如果您想使用 sendgrid 和 heroku,我也可以提供帮助。

因此,当涉及到我的 Gmail 身份验证设置时,我还必须允许安全性较低的应用程序,并解锁验证码。除了 Gmail 设置中的这两项更改之外,我还必须转到我的 Gmail 设置 > 转发和 POP/IMAP>,然后单击启用 IMAP。保存您的更改。这些都是我对我的 Gmail 所做的所有更改。

进行以下更改:

config/initializers/setup_mail.rb 将身份验证更改为:plain

if Rails.env.development? || Rails.env.production?
        ActionMailer::Base.delivery_method = :smtp
        ActionMailer::Base.smtp_settings = {
            address:        'smtp.gmail.com',
            port:           '587',
            authentication: :plain,
            user_name:      '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3841574d4a7d55595154785f55595154165b5755" rel="noreferrer noopener nofollow">[email protected]</a>',
            password:       'yourSecureGmailPassword',
            domain:         'mail.google.com',
            enable_starttls_auto: true
        }
     end

config/environments/test.rb 主机是一个网站,因为我使用的是cloud9

config.action_mailer.default_url_options = { host: 'https://blocipedia-sunnygoo.c9users.io', port: 3000 }

config/environments/development.rb

config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { host: 'same as in test.rb', port: 3000 }

应用程序/模型/user.rb

devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable

应用程序/mailers/application_mailer.rb

class ApplicationMailer < ActionMailer::Base
              default from: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f69084999bb6938e979b869a93d895999b" rel="noreferrer noopener nofollow">[email protected]</a>"
              layout 'mailer'
  end

应用程序/mailers/user_mailer.rb

class UserMailer < ApplicationMailer
               default from: "sunnydgoswami@@gmail.com"

               def new_user(user)
               @user = user
               mail(to: user.email, subject: "Welcome to Blocipedia!")
            end
         end

app/views/layouts/mailer.html.erb

          <html>
               <body>
                    <%= yield %>
               </body>
          </html>

app/views/layouts/mailer.text.erb

<%= yield %>

app/views/user_mailer/new_user.html.erb

'<!DOCTYPE html>
            <html>
                <head>
                     <meta content="text/html; charset=UTF-8" http-
                      equiv="Content-Type" />
                </head>
                <body>
                     <h1>Welcome, new user!</h1>
                     <p>
                         <%= @user.email %>, join us in creating a vibrant wiki 
                             atmosphere!
                     </p>
                     <p>
                          You signed up using <%= @user.email %>. You will be 
                          using this email next time to log in.
                     </p>
               </body>
             </html>'

关于ruby-on-rails-4 - Net::SMTPAuthenticationError,535-5.7.8 用户名和密码不被接受,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36037491/

相关文章:

ruby-on-rails - Ruby on Rails Mailer 在开发模式下不发送电子邮件

ruby-on-rails - Rails 邮件程序连接被拒绝 - localhost

ruby-on-rails - 使 pg_search 返回前缀和后缀的结果

ruby-on-rails - has_many 的表格 :through

javascript - 通过ajax调用渲染rails fields_for

python - IMAP、查看电子邮件标签、Python 和 Gmail

ruby-on-rails - Rails 4 中的 JS 和 CSS

google-api - Google API 发送带有附件的电子邮件 - REST API 调用 Postman

email - 无法使用 Delphi 从 Gmail 帐户下载/检索电子邮件(SSL3_GET_RECORD :wrong version number)

ruby-on-rails - 使用参数和参数测试 ActionMailer