Skip to content

Commit

Permalink
MDL-18903 All outgoing emails can be diverted into a single address
Browse files Browse the repository at this point in the history
This is highly useful when developing or debugging any emailing feature.
I am going to backport this after the end of the current Ice Age.
  • Loading branch information
mudrd8mz committed Mar 25, 2010
1 parent 581190f commit 49da4a5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config-dist.php
Expand Up @@ -360,6 +360,9 @@
// When working with production data on test servers, no emails should ever be send to real users
// $CFG->noemailever = true;
//
// Divert all outgoing emails to this address to test and debug emailing features
// $CFG->divertallemailsto = 'root@localhost.local';
//
// Specify prefix for fake unit test tables. If not specified only tests
// that do not need fake tables will be executed.
// $CFG->unittestprefix = 'tst_';
Expand Down
6 changes: 6 additions & 0 deletions lib/moodlelib.php
Expand Up @@ -4614,6 +4614,12 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a
return true;
}

if (!empty($CFG->divertallemailsto)) {
$subject = "[DIVERTED {$user->email}] $subject";
$user = clone($user);
$user->email = $CFG->divertallemailsto;
}

// skip mail to suspended users
if (isset($user->auth) && $user->auth=='nologin') {
return true;
Expand Down

0 comments on commit 49da4a5

Please sign in to comment.