邮寄给所有用户

时间:2015-06-08 12:26:00

标签: ruby-on-rails email

我想在发布文章时向所有用户发送邮件。我有这段代码:

梅勒类

class AdminMailer < ApplicationMailer
 def notification_mail(user)
   @user = user
   mail(to: @user.email, subject: '**TEST**')
 end
end

Article.rb

after_create :send_email_to_users    
def send_email_to_users
   User.all.each do |user|
     AdminMailer.notification_mail(user).deliver_now    
   end
end

配置

ActionMailer::Base.smtp_settings = {
  :user_name => 'simon.m@********.com',
  :password => '********',
  :address => 'smtp.*******.com',
  :port => 587,
  :authentication => :plain,
  :enable_starttls_auto => true
}

此代码似乎有效,因为当我发布一篇文章时,我可以在我的控制台上看到电子邮件已发送但我没有将它们收到我的邮箱。

CONSOLE

AdminMailer#notification_mail: processed outbound mail in 23.1ms

Sent mail to simon.m@*******.fr (30014.1ms)
Date: Mon, 08 Jun 2015 05:21:05 -0700
From: simon.m@******.com
To: simon.m@*********.fr
Message-ID: <557588b117179_ae53f7fcf56e0d0328b8@localhost.localdomain.mail>
Subject: **TEST**
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="--==_mimepart_557588b114e80_ae53f7fcf56e0d0327be";
 charset=UTF-8
Content-Transfer-Encoding: 7bit


----==_mimepart_557588b114e80_ae53f7fcf56e0d0327be
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: base64

VW5lIGlkw6llIHZpZW50IGQnw6p0cmUgcHVibGnDqWUKPT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0K

----==_mimepart_557588b114e80_ae53f7fcf56e0d0327be
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<html>
  <body>
    <!DOCTYPE html>
<html>
  <head>
    <meta content=3D'text/html; charset=3DUTF-8' http-equiv=3D'Content-Ty=
pe' />
  </head>
  <body>
    <h1>Une id=C3=A9e vient d'=C3=AAtre publi=C3=A9e </h1>
  </body>
</html>

  </body>
</html>

任何人都知道如何使其有效?

1 个答案:

答案 0 :(得分:1)

确保您的应用运行环境已启用投放和投放错误。

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

上次我这样做时,我必须在我的Google Apps帐户上启用安全性较低的应用,对您来说可能是相同的。没有任何错误很难说。访问https://www.google.com/settings/security/lesssecureapps即可启用该功能。 More info

确保Google未阻止您的IP。转到http://www.google.com/accounts/DisplayUnlockCaptcha,然后点击继续。 Source

看到某种错误会有助于缩小范围,但希望这会有所帮助!