[consulting] Using Test mail server in your local machine

Darrel O'Pry darrel.opry at gmail.com
Tue Aug 12 13:25:10 UTC 2008


I'm personally a fan of using the smtp_library configuration option to
hijack the mail sending process. I normally use something along the lines of
the following...

file: db_smtp.inc
==================================
/**
* Log the mails in db instead of mailing.
*/
function drupal_mail_wrapper($mailkey, $to, $subject, $body, $from,
$headers) {
  $mimeheaders = array();
  foreach ($headers as $name => $value) {
    // the check_plain nicely encodes <> chars for web presentation
    $mimeheaders[] = check_plain($name .': '. mime_header_encode($value));
  }
  db_query("INSERT INTO {db_smtp_mail}
                    (mailkey, mail_to, mail_from, subject, body, headers)
                   VALUES ('%s', '%s', '%s', '%s', '%s', '%s')",
            $mailkey, $to, $subject, $body, $from, implode("\n ",
$mimeheaders));
  return mysql_insert_id();
}

In my simple tests I just grab global $conf; and set $conf['smtp_library'] =
'path/to/db_smtp.inc'. This breaks if drupal_mail_wrapper is defined else
where. I really wish it were strip_extension($conf['smtp_library'])
.'_mail_wrapper() that was invoked instead of drupal_mail_wrapper, or
$conf['smtp_library'] referenced a module with the default being drupal.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/consulting/attachments/20080812/3adf51e1/attachment.htm 


More information about the consulting mailing list