【问题标题】:Action Mailer error: 535-5.7.8 Username and Password not acceptedAction Mailer 错误:535-5.7.8 用户名和密码不被接受
【发布时间】:2013-11-15 08:58:08
【问题描述】:

我有一个 Rails 应用程序,它使用表单收集消息详细信息并将消息通过电子邮件发送到我的 gmail/yahoo 帐户。

我已将此添加到 config/initializers 中的 setup_mail.rb:

ActionMailer::Base.smtp_settings = {  
      :address              => "smtp.gmail.com",  
      :port                 => 587,  
      :user_name            => "my_user",
      :password             => "my_pass", 
      :authentication       => "plain",  
      :enable_starttls_auto => true  
  }

并像这样将控制器用于 POST 路由:

def create
    @message = Message.new(params[:message])

    if @message.valid?
      NotificationsMailer.new_message(@message).deliver!
      redirect_to(root_path, :notice => "Message was successfully sent.")
    else
      flash.now.alert = "Please fill all fields."
      redirect_to('#')
    end
end

从表单中干净地接受消息参数,如下所示:

  Parameters: {"utf8"=>"✓", "authenticity_token"=>"4xgV0umvaTPzYxd18qdJq/GT7QCdXjrPTGR7D9R3AC4=", "message"=>{"name"=>"Deepak", "email"=>"deepakm.ccx@gmail.com", "subject"=>"Hi", "body"=>"Hi"}, "commit"=>"Send"}

无论我在设置中使用 Yahoo 凭据还是 Gmail 凭据,我都会不断收到相同的错误消息。我评论了 ActionMailer::Base.smtp_settings 中的所有设置,但仍然遇到此问题。这使我相信该问题可能与此代码之外的其他内容有关,但我没有任何线索。

-迪帕克

【问题讨论】:

  • 您是否允许外部连接在您的 Google 帐户偏好设置中发送电子邮件?
  • 我没有看到外发邮件的设置。我在 gmail 上启用了 IMAP 设置,但仍然是同样的错误。它是否正确?传出和传入的邮件都来自我的 gmail ID。
  • 当我遇到同样的问题并登录到谷歌邮件时,我在页面顶部看到有人想要从我的帐户向外部发送电子邮件的通知字符串。并且有一个按钮 - 要允许此操作(或类似的操作),请检查用户名是否以 @gmail.com 结尾
  • 感谢您的提示。我没有看到来自 gmail 的任何通知。事实上,我注释掉了所有 SMTP 设置,包括地址、用户名和密码,但仍然看到相同的错误消息“不接受用户名和密码”。好像 mail 命令正在创建一个 SMTP 通道,但它可能没有到达 gmail 服务器。

标签: ruby-on-rails actionmailer


【解决方案1】:

您提到您的代码在 config/initializers 中 - 我们有 ActionMailer 工作,它通过 Gmail 发送,但我们将其放入我们的 config/environments/developer.rb 文件中:

  #Send Email In Development (Use Gmail's Servers)
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_deliveries = true
  config.action_mailer.smtp_settings = {
      :address              => "smtp.gmail.com",
      :port                 => 587,
      :domain               => "*****.co.uk",
      :user_name            => "******@gmail.com",
      :password             => "******",
      :authentication       => :plain,
      :enable_starttls_auto => true
  }
  config.action_mailer.default_url_options = {
      :host => "localhost:3000"
  }

也许您可以尝试复制并粘贴上面的代码?

【讨论】:

  • 感谢您的提示。我尝试了这些设置,但没有添加域密钥,因为我没有使用谷歌应用程序,并启用了 IMAP。我收到相同的消息:535-5.7.8 用户名和密码不被接受。我可以做些什么来调试这个错误的来源?
  • 您确定可以使用 IMAP 发送吗?我确定这只是为了检索。也许这是个问题?
  • 根据文档,必须启用 IMAP 才能读取外部客户端上的消息,并且使用 SMTP 从外部客户端发送消息。我认为不需要为 ActionMailer 启用 IMAP 即可工作。 support.google.com/mail/troubleshooter/… 。会不会是防火墙的问题?
  • 是的 - 您似乎想通过您的 Rails 应用程序发送消息?在这种情况下,您需要使用 SMTP 协议发送邮件,然后通过 IMAP 将邮件发送到您的收件箱
【解决方案2】:

虽然我仍然无法通过 ActionMailer 发送电子邮件,但我想我会发布一个替代方案。

https://github.com/nu7hatch/gmail

运行良好且更容易,因为您不需要使用任何配置文件。

谢谢。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-22
    • 2021-08-05
    • 2023-03-22
    • 2022-08-12
    • 2020-12-16
    • 2017-11-29
    相关资源
    最近更新 更多