为什么我无法使用典型的 ActionMailer 配置从生产环境中的 Rails 发送电子邮件?

问题描述 投票:0回答:1

我查看了 535-5.7.8 用户名和密码在使用 Gmail 的 Rails Mailer 中不被接受,他们的问题与我的类似,我不确定他们是否已解决。

我在 Gmail 帐户上使用应用程序密码设置了 2fa。

我想通过该 Gmail 帐户向我们的用户发送帐户激活和密码重置电子邮件。

这是我的配置:

config.action_mailer.smtp_settings = {
    :address => 'smtp.gmail.com',
    :port => 587,
    :domain => 'appname.com',  # has not gone on line yet - does that matter?
    :user_name => ENV['GMAIL_APP_USER'],    # "[email protected]"
    :password =>  ENV['GMAIL_APP_PASSWORD'],
    :authentication => :plain,
    :enable_starttls_auto => true,
    :openssl_verify_mode => 'none',
  }
config.action_mailer.perform_caching = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => 'appname.com' } 
# again, it's not on line yet, but it seems like I need something
# I haven't found what exactly this field is for

每当我到达发送电子邮件的端点时,我都会在日志中看到以下内容:

I, INFO -- : Delivered mail [email protected] (287.1ms)
   [ ("MYHOSTNAME" is my actual hostname, but it's not mentioned in the above config) ]
I, INFO -- : Completed 500 Internal Server Error in 587ms (ActiveRecord: 16.5ms | Allocations: 18589)
F, FATAL -- :
Net::SMTPAuthenticationError (535-5.7.8 Username and Password not accepted. Learn more at
):

app/models/user.rb:35:in `send_activation_email'
app/controllers/account_activations_controller.rb:18:in `create'

从另一篇文章中我可以看到“了解更多”错误消息来自 gmail/google, 基本上那篇文章告诉我使用应用程序密码。

正在使用应用程序密码,并已在该电子邮件帐户上启用 2FA。

交付的应用程序密码由 4 组四字母序列组成, 每个后跟一个空格。无论我是否保留空格,我都会得到相同的结果 结果。

我需要做些什么才能让 gmail 知道这是一个应用程序密码, 而且我并没有泄露实际的账户密码?

我读过几十篇关于这个主题的文章,而且都说同样的事情。 让我觉得我没有做一些显而易见的事情。

代码在 github 中,但凭据不在。所以如果有人有兴趣 深入挖掘,请与我联系,我将解释我如何 将积分输入 Rails 应用程序。

ruby-on-rails gmail actionmailer
1个回答
0
投票

想通了...

请勿在

.rbenv-vars
文件中使用双引号引起来的秘密, 否则它们将成为实际字符串的一部分。

您可以从谷歌应用程序密码中删除空格。他们将它们分成四部分,这样您就可以在房间的另一边向您的同事大喊大叫,而不会忘记自己在哪里。

© www.soinside.com 2019 - 2024. All rights reserved.