How does the emailing system (drupal_mail) work in Drupal 6?
https://www.zyxware.com/sites/default/files/styles/user_image/public/pictures/zyxlogo.png?itok=J9t-ZEoU
BY webmaster
8 years ago
Web-Development
0 comments comment

Drupal uses a reasonably powerful mechanism to create, prepare and send emails generated within the system. We maintain two modules related to emails in Drupal - Mail Merge and MailQ (Mail Queue) - and get the opportunity to work with the mail subsystem in Drupal. Here is a brief write-up on how the mail system works in Drupal.

The workflow when sending a mail with drupal_mail

1) Module calls drupal_mail

drupal_mail($module, $key, $to, $language, $params = array(), $from = NULL, $send = TRUE)

The params array should have all the necessary information related to the mail that is to be sent. Do note that the mail is yet to be prepared and that will happen only during hook_mail calls.

2) drupal_mail then calls

2.a) hook_mail of the module calling drupal_mail

hook_mail is to be used by the module to copy parameters to $message.

The following parameters are already mapped back into $message from drupal_mail

  $message = array(
    'id'       => $module .'_'. $key,
    'to'       => $to,
    'from'     => isset($from) ? $from : $default_from,
    'language' => $language,
    'params'   => $params,
    'subject'  => '',
    'body'     => array()
  );

Drupal mail also sets the following as default headers

  $headers = array(
    'MIME-Version'              => '1.0',
    'Content-Type'              => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
    'Content-Transfer-Encoding' => '8Bit',
    'X-Mailer'                  => 'Drupal'
  );

If default_from is present it is used to set the following headers as well. default_from is either the site_mail if set or from php.ini sendmail_from parameter

  $headers['From'] = $headers['Sender'] = $headers['Return-Path'] = $headers['Errors-To'] = $default_from;
  $message['headers'] = $headers;

2.b) hook_mail_alter across all modules

Other modules can then alter $message as required via the hook_mail_alter call.

3) If $send parameter of drupal_mail is not set to FALSE drupal_mail will call drupal_mail_send

3.a) drupal_mail_send calls drupal_mail_wrapper($message) if smtp_library is set and the module is present. This is how the different modules like mimemail or smtp mail hooks into the mailing system in Drupal.

drupal_mail_wrapper is expected to send out the mail and if smpt_library is not set then drupal_mail_send will try to send out the mail using the php mail function.

How MailQ works in Drupal by plugging into drupal_mail

MailQ is a module designed to allow drupal sites hosted on shared hosting servers distribute the email loads on the system across time to work around the hourly email limits typically set by the hosting providers.

MailQ is designed to catch all mails sent by drupal by setting up a drupal_mail_wrapper which will queue all mails during non-cron regular site operations and which will send them out during cron runs. MailQ sets the smtp_library to itself forcing drupal_mail_send to call the drupal_mail_wrapper from mailq during normal operations. Mailq drupal_mail_wrapper will then store all the messages into the database queue and then process these in batches during cron runs by calling drupal_mail_send


RELATED ARTICLE

/themes/custom/zyxpro_light/images/placeholder.png
close

on 09th April 2007 / by webmaster
Freelance projects fall into a separate category of projects in that they target independent deve Community Projects Freelance Open Source Web Development Leave a reply Your email address will not be published. Required fields are marked * Shrinivasan (not verified) access_time 15 Dec 2019 - 06:53 Guys. Great Collection and a great site. It is really impressive to know that there a numerous FOSS tools for web contents. Thanks. Keep Growing. Anonymous (not verified) access_time 15 Dec 2019 - 06:53 In reply to Great collection by Shrinivasan (not verified) Great Collection and a great site!!! Thanks! Silvia (not verified) access_time 15 Dec 2019 - 06:53 Hi, nice work. I also love to use WordPress when setting up a new blog. Greetings JungleDirector (not verified) access_time 15 Dec 2019 - 06:53 Subj. Anybody have? I'ts better, if you have XRumer 5.04... Gimme link Thanks. Ingo (not verified) access_time 15 Dec 2019 - 06:53 Hi, this is a listing of open source software was looking for my new project Thx a lot Pagination Current page 1 Page 2 Page 3 Page 4 Page 5 Next page Next › Last page Last » Add new comment
Leave a reply
Your email address will not be published. Required fields are marked *

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type='1 A I'> <li> <dl> <dt> <dd> <h2 id='jump-*'> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
The content of this field is kept private and will not be shown publicly.
CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.