2

I see recommendations for Swiftmailer for handling bounce messages here, yet I don't see the support for this in the documentation. Am I missing something? It appears to me that PHPMailer-BHM is the only option out there with this feature ready to go out of the box. If this is incorrect, please elaborate.

I am asking because Swiftmailer looks to have the best documentation and support moving forward, but I don't want to spend time re-inventing the wheel creating a class to parse and handle the NDR's.

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108
Evil Elf
  • 2,157
  • 3
  • 22
  • 28

2 Answers2

11

Swiftmailer is more concerned with sending email (e.g. from your script to an SMTP server which handles the delivery). Swiftmailer has no capacity for receiving emails, which is what a bounce is.

The only time Swift could catch a bounce is if the SMTP server it's handing the email off to rejects the email outright. Otherwise, once it's queued in the SMTP server, Swiftmailer's done with it.

In real world terms, Swiftmailer is you walking a letter down the the mailbox. If the mailbox is welded shut, Swiftmailer will tell you, but otherwise the letter goes into the mailbox and then Swift's done.

A bounce is a letter carrier coming by the next day to drop off the envelope with 'return to sender' stamped on it. Swift has nothing to do with this, as it doesn't RECEIVE emails, it only walks them from your house to the mailbox.

Marc B
  • 356,200
  • 43
  • 426
  • 500
1

Setting the Return-Path: (Bounce) Address The Return-Path: address specifies where bounce notifications should be sent and is set with the setReturnPath() method of the message.

You can only have one Return-Path: and it must not include a personal name.

Bounce notifications will be sent to this address:

$message->setReturnPath('bounces@address.tld');
Payam Khaninejad
  • 7,692
  • 6
  • 45
  • 55
Engr James
  • 11
  • 1
  • 1
  • SwiftMailer should not set the "Return-Path" header at all, this is set by the receiving SMTP server to the value of the envelope sender ("MAIL FROM: " SMTP command). See also: http://stackoverflow.com/a/26765956 – imclean Jul 16 '19 at 00:44
  • Additional, setting setReturnPath doesn't work, see https://github.com/swiftmailer/swiftmailer/issues/949 - although the documentation of swiftmailer say so. https://swiftmailer.symfony.com/docs/messages.html#setting-the-return-path-bounce-address – sneaky Feb 12 '20 at 14:06
  • It does "work" as far as I can tell, it just may not have the outcome many are after. Setting the "Return-Path" header at the time of sending the message can result in that header being removed by an SMTP server (see http://www.postfix.org/cleanup.8.html ) or duplicate Return-Path headers after the final delivery SMTP server correctly adds it. – imclean Feb 12 '20 at 21:15