【发布时间】: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