Question

There are several modules that send email from my site: Rules, Trigger, User, ...

I am looking for a place to set a drupal_set_message() and print out the email contents. Where in the code would be the best place for that?

Was it helpful?

Solution

You can use hook_mail_alter() to get (and alter) the contents of an e-mail message before it gets sent out:

function mymodule_mail_alter(&$message) {
  dpm($message);
}

One thing to keep in mind is that not all modules use drupal_mail(), the function that'll call hook_mail_alter(), for various reasons. In that case, you'll have to identify where in the module's code the mail is sent out and see if they provide their own alter hooks: look for the functions drupal_alter('foo') (implemented via hook_foo_alter()), module_implements('foo'), module_invoke('foo'), or module_invoke_all('foo') (all implemented by hook_foo()).

Failing that, you may have to temporarily add the dpm() call directly to the module in the right place.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top