1

Possible Duplicate:
Swiftmailer 4 does not retrieve bounces as $failedRecipients

I am using SwiftMailer to send email through my GMail account using SMTP.

I have got everything setup perfectly and I can send emails without any problems.

The documentation says that send() should return 0 if no messages are sent successfully and populate an array (i've called it $failures), with the failed email addresses.

The issue I am seeing is that if I send an email to a non-existant address (asdfasdf@thisdomaindoesnotexist1111.com), I get a reply from GMail:

Mail Delivery Subsystem mailer-daemon@googlemail.com 
9:06 PM (6 minutes ago)
to me 
Delivery to the following recipient failed permanently:

     asdfasdf@thisdomaindoesnotexist1111.com

Technical details of permanent failure:
DNS Error: Domain name not found

----- Original message -----

However, swiftmailer still returns a 1 (1 message successfully sent) and the $failures array remains empty.

Since the connection is encrypted with SSL, I don't think I can sniff and look at the packets with wireshark.

My hunch is that GMail's SMTP server returns a success while it generates an email regarding the failure and sends it to the sending address.

Is this correct? If so, are there any ways to catch the failures in PHP?

Community
  • 1
  • 1
F21
  • 32,163
  • 26
  • 99
  • 170
  • Swiftmailer only send the email. The error message is comming later, Swiftmailer does not check for those. – hakre Jan 07 '12 at 12:19
  • Just a tip: you can check if a MX DNS record exist for that domain before actually trying to send an email: http://www.php.net/manual/en/function.checkdnsrr.php – JuCachalot Jan 07 '12 at 12:26

1 Answers1

0

Swift can only tell you if the SMTP server accepted the mail for delivery or not - cannot check for errors that appear later in the mail delivery process.

In your case, gmail's SMTP daemon did accept the message and failed when it tried to process it, this late you can only be notified this way.

If you want to programatically check these, you may write an IMAP client, that logs in to your gmail account and scans it for similar messages. Though I'm not sure it's worth the effort.

Maerlyn
  • 33,687
  • 18
  • 94
  • 85
  • 1
    I don't think it would be difficult. Setting the `Return-Path` to something like `bounce+uniqueid@mydomain.com` and then having a cron job that checks `bounce@mydomain.com` and collects those unique ids would work. Only issue here is that gmail replaces any custom `return-path` headers with your gmail address, but that's not the main issue here :) – F21 Jan 07 '12 at 12:39