发送一封电子邮件时,日志会显示该电子邮件两次?虽然只发送一次?
在我的应用程序中,DJ 发送了一封电子邮件,但由于某种原因,我在日志文件中看到该电子邮件两次,尽管它只发送一次?我在日志中确认 DJ 仅运行一次并且 user_mailer 仅运行一次。那么为什么我会在日志文件中看到该电子邮件两次? Rails 在做什么?
Rendered user_mailer/room_notification.text.erb (0.9ms)
Sent mail to [email protected] (1097ms)
Date: Fri, 30 Sep 2011 13:34:56 -0700
From: "roomxcom" <no-reply@roomxcom>
To: [email protected]
Message-ID: <[email protected]>
Subject: [Email Testing] Test 12
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
AAAAA Did something:
Test 12
http://localhost:3000/c19
Sent mail to [email protected] (3510ms)
Date: Fri, 30 Sep 2011 13:34:56 -0700
From: "roomxcom" <no-reply@roomxcom>
To: [email protected]
Message-ID: <[email protected]>
Subject: [Email Testing] Test 12
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
AAAAA Did something:
Test 12
http://localhost:3000/c19
SQL (0.1ms) BEGIN
AREL (0.3ms) DELETE FROM "delayed_jobs" WHERE "delayed_jobs"."id" = 25
SQL (0.4ms) COMMIT
延迟作业:
UserMailer.delay.room_notification(room, record.user, room_member.user, record.item)
用户邮件程序:
def room_notification(room, user_creator, user_recipient, item)
...
mail( :from => "XXXX <[email protected]>",
:to => user_recipient.email,
:subject => "[#{@room.title}] #{@item.title}"
).deliver
知道发生了什么以及为什么 Rails 在日志中显示电子邮件两次吗?谢谢
in my app, DJ fires off a an email but for some reason I see the email in the log file twice though it is sent only once? I confirmed in the logs that DJ runs only once and user_mailer runs only once. So why do I see the email twice in the log file? What is Rails doing?
Rendered user_mailer/room_notification.text.erb (0.9ms)
Sent mail to [email protected] (1097ms)
Date: Fri, 30 Sep 2011 13:34:56 -0700
From: "roomxcom" <no-reply@roomxcom>
To: [email protected]
Message-ID: <[email protected]>
Subject: [Email Testing] Test 12
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
AAAAA Did something:
Test 12
http://localhost:3000/c19
Sent mail to [email protected] (3510ms)
Date: Fri, 30 Sep 2011 13:34:56 -0700
From: "roomxcom" <no-reply@roomxcom>
To: [email protected]
Message-ID: <[email protected]>
Subject: [Email Testing] Test 12
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
AAAAA Did something:
Test 12
http://localhost:3000/c19
SQL (0.1ms) BEGIN
AREL (0.3ms) DELETE FROM "delayed_jobs" WHERE "delayed_jobs"."id" = 25
SQL (0.4ms) COMMIT
Delayed Job:
UserMailer.delay.room_notification(room, record.user, room_member.user, record.item)
User Mailer:
def room_notification(room, user_creator, user_recipient, item)
...
mail( :from => "XXXX <[email protected]>",
:to => user_recipient.email,
:subject => "[#{@room.title}] #{@item.title}"
).deliver
Any idea what' going on and why rails is showing the email in the log twice? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:现在是白天,我喝了一些咖啡,这里有一个更清晰的解释...
这一行将消息添加到队列中:
因此 Delayed_job 然后调用
UserMailer< 中的
room_notification
方法/code> 发送邮件:这本身就足以发送邮件,但在
mail
方法的末尾还有一个多余的.deliver
,因此它正在发送两次。TL;DR 在
room_notification
方法中从mail(...)
中删除.deliver
,一切都应该没问题。edit: Here's a clearer explanation now that it's daytime and I've had some coffee...
This line is adding the message to the queue:
So Delayed_job then calls the
room_notification
method inUserMailer
to send the mail:This would be enough in itself to send the mail but you also have a redundant
.deliver
on the end of themail
method so it's sending it twice.TL;DR Remove
.deliver
frommail(...)
in theroom_notification
method and everything should be fine.