I am using Swift Mailer to check for bounced messages. I have created one separate account for bounce messages, however when I set the return path, it does not allow the bounce message send to that account. Is it normal or is it a code error?
$verp = 'bounces-' . str_replace('@', '=', $row['ReplyTo']) . '@gmail.com';
$message = Swift_Message::newInstance()
->setSubject($row['Subject'])
->setFrom(array($row['ReplyTo'] => $row['FromName']))
->setReturnPath($verp)
->setBody($html, 'text/html')
->addPart($txt, 'text/plain');
I am now using VERP, it seems that it is to locate a delivery error? But not for sending the message to a bounce mail account?
Yes, that is normal. When sending email through Gmail's SMTP servers, it will force the return-path to be the account you are sending from.
Your only solution is to search for a provider which allows you to set the return-path.
It's not a gmail issue, it's a requirement of the SMTP specification, as defined in RFC 5321 section 4.4:
A message-originating SMTP system SHOULD NOT send a message that already contains a Return-path header field.
It also says that while SMTP systems should not inspect message content at all (i.e. they don't look at headers), a gateway from some other context to SMTP SHOULD remove any return-path header. In short, if you're adding a return-path header yourself, you're doing it wrong.
The return-path header you see in a received message is created by the receiver, not the sender, and is derived from the SMTP MAIL FROM
command used to deliver the message. This address need not to have anything in common with the From address header within the message, and designates where the message should be sent to in the event of a delivery failure, i.e. exactly what you want the VERP address for.
I don't know about SwiftMailer, but in PHPMailer you can set the SMTP envelope sender value by setting the Sender
property, and a receiver will convert that into a return-path message header on reception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With