Custom mail delivery for Drupal 6

here's the summary Conversation with that Customer asking to replace Drupal mail system with a custom one:

Request: Please, replace Drupal mail system with another mail delivery system [php code]

Verifing requisites:

  • Do you have your custom sendmail php function?: Yes [in this case, we have a php function named "my_custom_send_mail" using the Amazon SES Web Service ]
  • Do you accept hacking your Drupal core*?: Yes [being as lighter as possible, please]

* = Haking Drupal core is usually a bad idea. In this case, replacing one mail delivery with another, it easier to accept the idea of an "unpure" Drupal core.


That said, we can finally, we go and implement custom mail delivery, replacing Drupal core mail delivery system.

  • Step:1) in your includes/mail.inc, rename drupal_mail_send as drupal_mail_send_SOSP. Row 172sh should be
    function drupal_mail_send_SOSP($message) {


  • Step:2) Create a new empty function in your custom module

    function drupal_mail_send($message) {
    $params = Array();
    $params['subject'] = $message['subject'];
    $params['message'] = $message['body'];
    $res = my_custom_send_mail ($module = 'nu', $key, $message['to'], $message['language']->language,$params,$message['from'], $send = TRUE) ;
    return $res['result'];
    }

    note : be sure your custom "drupal_mail_send()" will return some kind of message ( return $res['result']; ). Otherwise $messages will give you a "Unable to send e-mail. Please contact the site administrator if the problem persists."



That's it!
From now on, every mail message sent from your Drupal 6 webiste will go through your custom mail delivery, replacing default system, and can safely stop your server MPA [ example /etc/init.d/postfix stop]

Need to roll back to the original default mail delivery system?

Simply switch back function names and you'll be allright!