Actionmailer不传送邮件,带有导轨3 [英] Actionmailer not delivering mail, with rails 3

查看:70
本文介绍了Actionmailer不传送邮件,带有导轨3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个应用程序,该应用程序在用户注册时发送电子邮件。

I am trying to make an application, that sends an email when user registers.

我在config / application.rb文件中输入了gmail的smtp设置邮件功能如下:

i put in the smtp settings for gmail in the config/application.rb file and the mail function looks like

mail(:to => "me@me.com", :subject => "Mail!", :from => "another@me.com", :content_type => "text/html")

现在,当我看到日志时,我看到它说邮件已经发送,但是我根本没有收到任何邮件...

now when i see the logs, i see that it says mail has been sent, but i never receive any mail at all...

此外,当我调用邮件传递功能 Emails.signed(@user).deliver 时,表单页面不会重定向,但是如果我注释掉电子邮件,它就可以工作

also, when i call the mail deliver function, Emails.signed(@user).deliver, the form page does not redirect, but it works if i comment out the email sending code that is either

Emails.signed(@user).deliver

mail(:to => "me@me.com", :subject => "Mail!", :from => "another@me.com", :content_type => "text/html")

谢谢:)

编辑:developme nt.rb

development.rb

App::Application.configure do
  # Settings specified here will take precedence over those in config/environment.rb

  # In the development environment your application's code is reloaded on
  # every request.  This slows down response time but is perfect for development
  # since you don't have to restart the webserver when you make code changes.
  config.cache_classes = false

  # Log error messages when you accidentally call methods on nil.
  config.whiny_nils = true

  # Show full error reports and disable caching
  config.consider_all_requests_local       = true
  config.action_view.debug_rjs             = true
  config.action_controller.perform_caching = false

  # Don't care if the mailer can't send
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_deliveries = true

  # Print deprecation notices to the Rails logger
  config.active_support.deprecation = :log

end


推荐答案

有些晚了,但是尽管如此,这也许可以省下几个小时的脑筋急转弯。这可能仅与从gmail发送电子邮件有关。
首先,为了帮助调试情况,请将development.rb中的以下行设置为true(假设您处于开发模式):

Somewhat late, but nevertheless maybe this will save someone a few hours of head banging. This is probably only relevant to sending emails from gmail. First, in order to help debugging the situation, set the following line in development.rb to true (assuming you're in development mode):

config.action_mailer.raise_delivery_errors = true

这将使ActionMailer不能默默地忽略错误。
当我这样做时,我意识到gmail正在拒绝我的用户名和密码。
然后我进入配置文件,在其中放置了所有Action Mailer配置指令(对我来说,它位于development.rb中,可能有个更好的放置位置),并注意到:user_name设置为 admin而不是 admin@thedomain.com。更改它可以解决问题。这是我对development.rb的更正部分:

This will make ActionMailer not to silently ignore errors. When I did that, I realized gmail is refusing my username and password. I then went to my configuration file where I put all the Action Mailer config directives (for me it was in development.rb, there is probably a better place to put it), and noticed that :user_name was set to "admin" rather than "admin@thedomain.com". Changing it solved the problem. Here is my corrected part of development.rb:

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :domain               => 'thedomain.com',
  :user_name            => 'admin@thedomain.com',
  :password             => '<password>',
  :authentication       => 'plain',
  :enable_starttls_auto => true  }

参考:

http://forums.pragprog.com/forums/43/topics/541
http://edgeguides.rubyonrails.org/action_mailer_basics.html

这篇关于Actionmailer不传送邮件,带有导轨3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆