Problem/Motivation

When sending mails to a sandbox test domain through MailgunMail::queueMessage() the mail will be rejected by the sandbox domain unless the recipient is in the allowed list, with the following error:

Domain sandbox.mailgun.org is not allowed to send: Sandbox subdomains are for test purposes only. Please add your own domain or add the address to authorized recipients in Account Settings.

The mail is currently not removed from the queue so it will be resent again and again on the next cron run. This results in an endless stream of errors.

Steps to reproduce

  1. Configure the module to use a sandbox domain.
  2. Queue a message to a recipient which is not listed as an "authorized recipient" in the sandbox domain.

Result: the mail is rejected by the sandbox and is sent again and again on every cron run.

Expected result: the mail is rejected by the sandbox and is not sent again.

Proposed resolution

When the Mailgun API indicates in their error message that the mail is rejected due to being sent through a sandbox domain, the message should be removed from the queue.

Remaining tasks

First we need to fix #3346666: MailgunHandlerInterface::sendMail() should throw exceptions on error before this can be implemented.

Issue fork mailgun-3346676

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pfrenssen created an issue. See original summary.

hazn’s picture

Beautiful changes, approved in review :)