development.log中没有错误,但邮件不会被发送

时间:2011-12-07 09:20:32

标签: ruby-on-rails email smtp actionmailer

我使用ActionMailer通过Rails发送电子邮件,但我收不到任何内容。

我的development.log说:

Sent mail to mymail@gmail.com (2107ms)
Date: Wed, 07 Dec 2011 17:14:30 +0800
From: no-reply
To: mymail@gmail.com
Message-ID: <4edf2e765a139_147105390c874e3@raincole-laptop.mail>
Subject: Reset password instructions
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<p>
  Hello mymail@gmail.com!
</p>
<p>Someone has requested a link to change your password, and you can do this through the link below.</p>
<p><a href="http://starfish.dev/users/password/edit?reset_password_token=vHtzByZmDPcS4FhcwUPP">Change my password</a></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>

但我的收件箱或垃圾邮件箱中没有任何新内容。

我已经设定:

ruby-1.9.2-p290 :008 > Rails.application.config.action_mailer[:raise_delivery_errors]
 => true 

那么,我怎样才能看到要调试的真实错误日志?

修改

我写了email.yml

development:
  reply: "no-reply"
  host: "starfish.dev"
  smtp: 
    address: "smtp.gmail.com"
    port: 587
    domain: "starfish.dev"
    authentication: "plain"
    user_name: "mymail@gmail.com"
    password: "mypassword"
    enable_starttls_auto: true

然后在application.rb

$EMAIL_CONFIG = ActiveSupport::HashWithIndifferentAccess.new YAML.load(File.open("#{Rails.root}/config/email.yml"))[Rails.env]
config.action_mailer.smtp_settings = $EMAIL_CONFIG[:smtp].symbolize_keys if !$EMAIL_CONFIG[:smtp].nil?
development.rb中的

config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true

但是,它仍然只发送到日志文件,不发送到真实地址。

2 个答案:

答案 0 :(得分:0)

开发和测试环境不使用真正的邮件程序(除非您专门配置它们)。默认情况下,它完全按照您的注意事项执行:它会经历发送电子邮件的所有动作......但实际上并未发送,只记录本已发送的电子邮件。

编辑:请注意,这是对原始问题的回复,该问题不包含任何smtp设置。

答案 1 :(得分:0)

你试过telnet smtp.yoursite.com 587吗? 如果没有响应,请检查您的防火墙。