Actionmailer SMTP 服务器响应
当通过actionmailer发送邮件时,actionmailer会从SMTP服务器获取响应,无论何时正常,或者何时错误。有没有办法在发送邮件后检索此回复? 另外,当 SMTP 服务器没有抛出错误时?
我们的 qmail 邮件服务器抛出一个处理程序 ID,我们想用它来跟踪电子邮件。
例如,服务器响应如下:
250 ok 1308235825 qp 17832
When sending mail through actionmailer, the actionmailer gets a response from the SMTP server, when its ok, or when its wrong. Is there a way to retrieve this response after sending a mail?
Also when no errors are thrown by the SMTP server?
Our qmail mail server throws a handler id which we want to use for tracing e-mails.
As an example, the server response is this :
250 ok 1308235825 qp 17832
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 smtp 设置中设置
return_response: true
并调用message.deliver!
而不是deliver
。这将返回 SMTP 服务器响应,即Net::SMTP::Response
,其中包含您要查找的服务器响应。如果您需要与服务器连接的所有响应的日志,而不仅仅是最终结果,则需要深入研究 Net::SMTP。
Set
return_response: true
in the smtp settings and callmessage.deliver!
instead ofdeliver
. This returns the SMTP server response, aNet::SMTP::Response
, which contains the server response you're looking for.If you need a log of all responses from the connection with the server, not just the final result, you'll need to dig into Net::SMTP.
查看源代码,您可以定义一个观察者:
在 base.rb
因此,您可以在初始化文件中使用类似这样的代码:
这将记录发送的邮件,您可以查看是否可以从发送的邮件对象获取标头或响应。
Looking at the the source you can define an observer:
in base.rb
So you could use some code like this in an initialization file:
That will log sent mail and you can see if you can get the headers or response from the sent mail object.