ArgumentError已请求SMTP-AUTH,但缺少用户名

问题描述

我正在开发一个名为PhotoApp的基本应用程序,在那里我将学习如何使用Rails设置SMTP。之前我已经在SMTP上使用了基本的Ruby,而且我知道我的电子邮件有效,只是发送的电子邮件进入了垃圾邮件文件夹。

但是当我尝试在Rails上配置SMTP时,我得到ArgumentError (SMTP-AUTH requested but missing user name):,这就是当用户注册时将应用程序推送到heroku时崩溃的主要原因。

Error Image


这是我的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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...