From 49da4a5fa85ea67c76d872d8a5fd5c6037655a8b Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Thu, 25 Mar 2010 01:29:02 +0000 Subject: [PATCH] MDL-18903 All outgoing emails can be diverted into a single address 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. --- config-dist.php | 3 +++ lib/moodlelib.php | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/config-dist.php b/config-dist.php index 1cdf4b3d460..501865d6d78 100644 --- a/config-dist.php +++ b/config-dist.php @@ -360,6 +360,9 @@ $CFG->admin = 'admin'; // 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_'; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 4d0e1d6589b..0b8f76e4974 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -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;