Swift Mailer传递状态 [英] Swift Mailer Delivery Status

查看:113
本文介绍了Swift Mailer传递状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道SwiftMailer发送功能是否返回发送状态?我想知道电子​​邮件已发送或未发送.这可能吗?

Does anyone know if SwiftMailer send function returns delivery status? I would like to be able to know that email was delivered or not delivered.Is this possible?

谢谢

推荐答案

SwiftMailer至少支持三层检查,这些检查将报告几种交付失败类型.

There are at least three layers of checks that SwiftMailer supports, that will report several types of delivery failures.

1)始终检查SwiftMailer的send()或batchSend()命令的返回码是否为非零结果.从文档:

1) Always check the return code from SwiftMailer's send() or batchSend() commands for a non-zero result. From the documentation:

//Send the message
$numSent = $mailer->send($message);

printf("Sent %d messages\n", $numSent);

/* Note that often that only the boolean equivalent of the
   return value is of concern (zero indicates FALSE)

if ($mailer->send($message))
{
  echo "Sent\n";
}
else
{
  echo "Failed\n";
}

2)使用按引用失败功能来了解特定地址是否(es)被拒绝或无法完成:

2) Use the failures-by-reference feature to know if specific address(es) were rejected or couldn't complete:

//Pass a variable name to the send() method
if (!$mailer->send($message, $failures))
{
  echo "Failures:";
  print_r($failures);
}

/*
Failures:
Array (
  0 => receiver@bad-domain.org,
  1 => other-receiver@bad-domain.org
)
*/

3)在某些情况下,您可能还想启用退货收据 ,确认电子邮件阅读器显示了该消息.它们通常被用户或其电子邮件应用程序禁用或忽略,但是,如果您收到收据,则具有很高的确认性.还请注意,这可能在发送后的许多天发生,因此它不是像上面的两个实时同步测试.

3) In a few situations you might want to enable return receipts as well, which confirm that an email reader displayed the message. They often are disabled or ignored by users or their email apps, but if you get a receipt, it is highly confirmatory. Note also that this might occur many days after sending so it's not a real-time synchronous test like the two above.

$message->setReadReceiptTo('your@address.tld');

但是,由于SMTP传递涉及太多变量和系统层,因此通常不可能绝对确定是否已传递消息.您能做的最好的事情就是确保您正在使用上面的前两个检查.如果您将自己的服务器用于SMTP服务,那么您还需要注意Marc B提到的日志和队列.

However, since there are so many variables and layers of systems involved in SMTP delivery, it is not generally possible to be absolutely sure messages were delivered. The best you can do is make sure you're using the first two checks above. If you're using YOUR own server for the SMTP service, then you ALSO need to be watching your logs and queues as Marc B mentioned.

另一个示例强调需要熟悉您所使用的任何基础电子邮件系统.我刚刚开始将John Hobbs的Swift_AWSTransport用于Amazon Web Services SES. SES能够针对通过它发送的每条消息返回带有诊断信息的XML响应.尽管SwiftMailer并不是天生就了解如何使用XML响应,但是我发现它对于故障排除交付非常有用.我之所以提到它,是因为我发现在某些情况下,上面的#1和#2检查对SwiftMailer似乎是成功的,但是SES不喜欢我的消息格式.因此,我正在考虑将XML解析为附加检查.

One other example that emphasizes the need to get familiar with whatever underlying email system you're using. I've just started using the Swift_AWSTransport by John Hobbs for Amazon Web Services SES. SES has the ability to return an XML response with diagnostic information for each message sent through it. Though SwiftMailer doesn't inherently understand how to use that XML response, I have found it invaluable for troubleshooting delivery. I mention it because I found that in some cases, checks #1 and #2 above will appear successful to SwiftMailer, yet SES didn't like something about my message formatting. I'm therefore looking into parsing that XML as an additional check.

这篇关于Swift Mailer传递状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆