Mandrill maintains a "Rejection blacklist" of email address for which mail sending fails. When this happens the mandrill module, in mandrill_mailsend():
1) logs the events in watchdog e.g. "Failed sending email from site@example.co.uk to you@hotmail.co.uk. rejected: no message". (The "no message" is added by the Drupal module because no reason message is returned by mandrill. )
2) Returns TRUE, thus telling the sending process that the mail was sent successfully, which is untrue in this case.

A similar flow would occur for sends resulting in "error" or "invalid" status.

The mandrill module should tell the sending process that the mail failed so that it can queue the mail for sending on another occasion if necessary.

Items on the blacklist expire after a certain time - from a week to a year. It would be useful to know this info so that the calling process could decide whether to retry the mail in a week or give up.

More info on blacklists at http://help.mandrill.com/entries/22880521-What-is-a-rejected-email-Rejec...

Comments

hughworm’s picture

Issue summary: View changes
JordanMagnuson’s picture

It would also be nice to have a hook invoked whenever an email is rejected by Mandrill, so that other modules can act on the event and decide to, for example, delete the user account.

nbchip’s picture

Adding hook (mandrill_message_result?) to mandrill.module Line 151 would allow us to react on message status and also use message _id, which i would like to store in my DB (for possible message threading reasons)

nbchip’s picture

Sendgrid module does something similar

module_invoke_all('sendgrid_integration_sent', $message['to'], $result->code, $smtp_api['unique_args'], $result_data);

 function hook_sendgrid_integration_sent($to, $result_code, $unique_args, $result_data) {
   if($unique_args['module'] == 'my_module' && $result_code = 200) {
     watchdog('My Module', 'My module has successfully sent email', NULL, WATCHDOG_NOTICE, $link = NULL);
   }
 }

Also adding failed messages to queue for resending seems as a good idea from sendgrid module

levelos’s picture

Status: Active » Fixed

I'm on board with the hook and returning FALSE in the case of an error. Ref. 975a014.

  • Commit 975a014 on 7.x-1.x by levelos:
    #2130153 by levelos: Allow other modules to react a message send result.
    

  • Commit 975a014 on 7.x-1.x, 7.x-2.x by levelos:
    #2130153 by levelos: Allow other modules to react a message send result.
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Martijn Houtman’s picture

Just a quick question: when an email address is blacklisted, Drupal displays an error to the user. I really want to prevent this in case of 'rejected'. This hook uses module_invoke_all(), which does not allow any altering, nor can the hook return a value. This means we can not change the behaviour, e.g. ignoring the error by returning TRUE in the hook.

Any idea how to deal with this?