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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1927064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 22:03:12  来源:igfitidea点击:

ActionMailer emails "sent" in development.log, but not received

ruby-on-railsrubyactionmailer

提问by user117046

I'm having problems actuallysending via ActionMailer in development, on my localhost, with Rails 2.3.2and Ruby 1.8.6. The development.log shows that it has "sent" the email with no errors, but the email is not received. I have tried multiple email addresses for sending and receiving and have tried multiple configs and plugins, but cannot get the email to send. Any help would be much appreciated - I feel like I'm dancing around a bunch of versions of solutions for different versions of rails and ruby and can't nail it down. I would much appreciate any comments. Thanks!

我在开发中通过 ActionMailer 在我的本地主机上使用Rails 2.3.2Ruby 1.8.6实际发送时遇到了问题。development.log 显示它已经“发送”了没有错误的电子邮件,但没有收到电子邮件。我尝试了多个用于发送和接收的电子邮件地址,并尝试了多个配置和插件,但无法发送电子邮件。任何帮助都将不胜感激 - 我觉得我正在为不同版本的 rails 和 ruby​​ 解决方案的一堆版本跳舞并且无法确定它。我将不胜感激任何意见。谢谢!

Plugins:

插件:

  • action mailer optional tls
  • smtp_tls
  • 动作邮件可选 tls
  • smtp_tls

Different email configs:

不同的电子邮件配置:

  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 => '[email protected]',
    :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 [email protected]

Date: Fri, 18 Dec 2009 00:27:06 -0800
From: Test Email Acct <[email protected]>
To: [email protected]
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--

回答by Justin Tanner

Put the following in config/environments/development.rb

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

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

It will override the settings in config/environment.rb

它将覆盖中的设置 config/environment.rb

Also for rails 2.Xyou'll need to setup:

同样对于导轨,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      => "[email protected]",
  :password       => "secret_passsword",
  :authentication => :plain
}

回答by sarahhodne

You need to use trueand not :true.

您需要使用true而不是:true.

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

回答by Vinay

In case anyone faces this problem, set "config.action_mailer.raise_delivery_errors = true" in development.rb in your environments folder and try sending mail again. This should raise whatever error is being encountered.

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

Sometimes in line 8 of smtp_tls.rb , the check_auth_args method accepts only 2 arguments : user and secret. Remove the 'authtype' argument if you see it and try again. Should work.

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