ActionMailer电子邮件在development.log中“发送”,但未收到

时间:2009-12-18 08:44:31

标签: ruby-on-rails ruby actionmailer

我在 Rails 2.3.2 Ruby 1.8.6 中,通过ActionMailer在开发中,在我的localhost上发送实际的问题。 development.log显示它已“发送”了没有错误的电子邮件,但未收到电子邮件。我已尝试多个电子邮件地址进行发送和接收,并尝试了多个配置和插件,但无法收到要发送的电子邮件。任何帮助都将非常感激 - 我觉得我正在为不同版本的导轨和红宝石的一系列解决方案跳舞,并且无法将其钉死。我非常感谢任何评论。谢谢!

插件:

  • 动作邮件程序可选tls
  • smtp_tls

不同的电子邮件配置:

  ActionMailer::Base.smtp_settings = {
    :enable_starttls_auto => true, #works in ruby 1.8.7 and above
    :address => 'smtp.gmail.com',
    :port => 587,
    :domain => 'example.com',
    :authentication => :plain,
    :user_name => 'testacct',
    :password => 'secret'
  }

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :tls => :true,
    :address => 'smtp.gmail.com',
    :port => 587,
    :authentication => :plain,
    :user_name => 'testacct@gmail.com',
    :password => 'secret'
    #:enable_starttls_auto => true # for rails >= 2.2 && ruby >= 1.8.7
  }
  config.action_mailer.perform_deliveries = :true #try to force sending in development 
  config.action_mailer.raise_delivery_errors = :true 
  config.action_mailer.default_charset = "utf-8"

Development.log:

Sent mail to sa23kdj@trash2009.com

Date: Fri, 18 Dec 2009 00:27:06 -0800
From: Test Email Acct <testacct@gmail.com>
To: sa23kdj@trash2009.com
Subject: Signup
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=mimepart_4b2b3cda9088_634334302a5b7


--mimepart_4b2b3cda9088_634334302a5b7
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww=
w.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang=3D'en' xml:lang=3D'en' xmlns=3D'http://www.w3.org/1999/xhtml'>=

  <head>
    <meta content=3D'text/html;charset=3DUTF-8' http-equiv=3D'content-typ=
e' />
  </head>
  <body>
    Welcome Email
    <p>
      user name:
      lfglkdfgklsdf
      activation link:
      http://localhost:3000/login
    </p>
  </body>
</html>

--mimepart_4b2b3cda9088_634334302a5b7--

3 个答案:

答案 0 :(得分:14)

将以下内容放入config/environments/development.rb

config.action_mailer.perform_deliveries = true 
config.action_mailer.raise_delivery_errors = true

它将覆盖config/environment.rb

中的设置

对于导轨2.X,您还需要设置:

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

答案 1 :(得分:8)

您需要使用true而不是:true

:tls => true
...
config.action_mailer.perform_deliveries = true #try to force sending in development 
config.action_mailer.raise_delivery_errors = true 

答案 2 :(得分:4)

如果有人遇到此问题,请在您的环境文件夹中的development.rb中设置“config.action_mailer.raise_delivery_errors = true”,然后尝试再次发送邮件。这应该会引起遇到的任何错误。

有时在smtp_tls.rb的第8行中,check_auth_args方法只接受2个参数:user和secret。如果您看到它,请删除'authtype'参数,然后重试。应该管用。