如何解决ArgumentError已请求SMTP-AUTH,但缺少用户名
我正在开发一个名为PhotoApp的基本应用程序,在那里我将学习如何使用Rails设置SMTP。之前我已经在SMTP上使用了基本的Ruby,而且我知道我的电子邮件有效,只是发送的电子邮件进入了垃圾邮件文件夹。
但是当我尝试在Rails上配置SMTP时,我得到ArgumentError (SMTP-AUTH requested but missing user name):
,这就是当用户注册时将应用程序推送到heroku时崩溃的主要原因。
这是我的config / environments / development.rb:
config.action_mailer.default_url_options = { host: 'localhost:8080' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',port: 587,domain: 'example.net',authentication: 'plain',enable_starttls_auto: true,user_name: 'gmail_email',password: '...'
}
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
我正在开发模式下在localhost:8080上运行服务器,因此我的主机设置为localhost:8080。
除此之外,我无法在rails中使用SMTP的Gmail用户名来使用我的应用。
编辑,此红宝石代码有效:
#!/usr/bin/ruby -w
require 'net/smtp'
message = <<~EOF
From: mygmail@gmail.com
To: someone@protonmail.com
Subject: Hello!
Hello!
#{"HELLO ".*(50).delete_suffix(?\s)}
EOF
Net::SMTP.new('smtp.gmail.com',587).tap(&:enable_starttls_auto).start('gmail.com','mygmail@gmail.com','mygmailpass',:plain) do |smtp|
smtp.send_message message,'someone@protonmail.com'
end
但是,作为Rails的新手,当配置文件中使用相同的电子邮件时,我无法使actionmailer工作...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。