Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not receiving Amazon SES Bounce Notifications

I have configured postfix on my server to deliver only @gmail.com mails to Amazon SES:

gmail.com          smtp:email-smtp.eu-west-1.amazonaws.com:25
*                  :

Also, I configured in the Amazon SES console to receive Bounces and Complains on mail using Amazon SNS. The problem is that I don't receive a bounce if I send a mail to a non-existent gmail address.

If sending a mail from mail.google.com to the address [email protected] I receive:

Delivery to the following recipient failed permanently:
 [email protected]

But If sending from a PHP script to the same address, postfix says:

E4E1A9F9CE: to=<[email protected]>, relay=email-smtp.eu-west-1.amazonaws.com[54.72.42.170]:25, delay=21, delays=0.02/0.04/11/10, dsn=2.0.0, status=sent (250 Ok 00000146d86bcc13-9fa1ac16-b1cd-476e-8398-31f406d47961-000000)

So Amazon SES accepts the mail but I don't get notified of the failure. What can be wrong?

Note. When sending to valid emails, everything works as expected.

Also, when sending a test mail from AWS SES console to [email protected], I am immediately notified via email, but sending to the same email from a PHP script via email-smtp.eu-west-1.amazonaws.com does not results in an email notification.

like image 746
Victor Dodon Avatar asked Jun 26 '14 13:06

Victor Dodon


People also ask

How do I get SES notifications?

Open the Amazon SES console. In the navigation pane, choose Verified identities. Then, select the verified domain or email address that you want to get bounce notifications for. Select the Notifications tab, and then choose Edit in the Feedback notifications panel.

What is bounce in AWS SES?

Amazon SES will categorize your hard bounces into two types: permanent and transient. A permanent bounce indicates that you should never send to that recipient again.


1 Answers

I was facing the same problem. In my case, I'm using the PHPMailer library (https://github.com/PHPMailer/PHPMailer/) and I solved it by specifying a Sender of the message.

/**
 * The Sender email (Return-Path) of the message.
 * If not empty, will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
 * @type string
 */
public $Sender = '';

I setted it to the same address as the $From and I now receive the bounces in the expected address.

So this is my working code:

$this->mail = new PHPMailer();
$this->mail->CharSet = 'utf-8';
$this->mail->From = $from_address;
$this->mail->Sender = $from_address;
$this->mail->FromName = $from_name;
$this->mail->Subject = $subject;
$this->mail->Body    = $body;
$this->mail->AltBody = $altBody;
$this->mail->addAddress($to_address, $to_name);
$this->mail->send()

If you use the setFrom method in PHPMailer, it will also set automatically the Sender to the same address.

/**
 * Set the From and FromName properties.
 * @param string $address
 * @param string $name
 * @param boolean $auto Whether to also set the Sender address, defaults to true
 * @throws phpmailerException
 * @return boolean
 */
public function setFrom($address, $name = '', $auto = true)
like image 143
Maria Vilaró Avatar answered Oct 08 '22 00:10

Maria Vilaró