【问题标题】:Net::SMTPAuthenticationError, 535-5.7.8 Username and Password not acceptedNet::SMTPAuthenticationError,535-5.7.8 用户名和密码不被接受
【发布时间】:2023-03-22 09:45:02
【问题描述】:

我知道这个问题已经回答了很多次,但我仍然无法弄清楚我的参数有什么问题。

我已经修改了我的 gmail 帐户,因此它允许使用安全性较低的应用程序,并使用验证码将其解锁,但它仍然认为我的用户名和密码不被接受,即使我确定它们,因为我检查了 3 次已经

这是我的文件:

config/environments/production.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            => "mymail@gmail.com",
      :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 => "myemail@gmail.com",
    :password => 'myPassword',
    :authentication => :login,
    :enable_starttls_auto => true
}

我想我做错了什么,或者把一些东西放在了不属于它的地方,但是我看到了很多不同的方法,以至于我迷路了

提前谢谢你

【问题讨论】:

    标签: ruby-on-rails-4 gmail actionmailer


    【解决方案1】:

    我是初学者,这是我第一次在 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:      'yourEmail@gmail.com',
                password:       'yourSecureGmailPassword',
                domain:         'mail.google.com',
                enable_starttls_auto: true
            }
         end
    

    config/environments/test.rb host 是一个网站,因为我使用的是 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 }
    

    app/models/user.rb

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

    app/mailers/application_mailer.rb

    class ApplicationMailer < ActionMailer::Base
                  default from: "from@example.com"
                  layout 'mailer'
      end
    

    app/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>'
    

    【讨论】:

    • 您应该为这个完整的答案获得前 5 个 SO 投票,但生活告诉我,像 mailgun 这样的服务,让 Gmail 单独使用会更好、更安全 :)
    猜你喜欢
    • 2016-07-05
    • 1970-01-01
    • 2016-05-22
    • 2020-02-05
    • 2021-08-05
    • 2022-08-12
    • 2020-01-19
    相关资源
    最近更新 更多