-
Improvement
-
Resolution: Won't Fix
-
Minor
-
None
-
4.4.3
-
None
-
MOODLE_404_STABLE
Hi all,
to properly determine the SMTP Port to use for sending outbound email traffic, i suggest the following patch:
diff --git a/lib/moodlelib.php b/lib/moodlelib.php
|
index dc8ae615663..b9aaa80b986 100644 |
--- a/lib/moodlelib.php
|
+++ b/lib/moodlelib.php
|
@@ -5458,6 +5458,14 @@ function get_mailer($action='get') { |
// Use previous keepalive. |
$mailer->SMTPKeepAlive = $prevkeepalive;
|
|
+ if (strcmp($CFG->smtpsecure, 'ssl') == 0) { |
+ $mailer->Port = 465; |
+ } else if (strcmp($CFG->smtpsecure, 'tls') == 0) { |
+ $mailer->Port = 587; |
+ } else { |
+ $mailer->Port = 25; |
+ }
|
+
|
|
if ($CFG->smtpuser) { |
// Use SMTP authentication. |
$mailer->SMTPAuth = true; |
But why this patch is needed?
It is possible to input an SMTP-Server under Website-Administration->Server->Outbound E-Mails. This SMTP Server can also have a port attached (like mail.moodle.org:465). When the SMTP Server is configured to use another port for implicit TLS (called SSL in the Moodle UI), it is neccessary to be able to configure a port on this way. But when no port is given, the smtpsecure option seems not to be considered at all. So when the SMTP-Server is mail.moodle.org and the SMTP-Security is SSL, no connection is possible. The connecttion will be established successfully, when the port is added to the SMTP-Server (mail.moodle.org:465).
With the above patch, it is possible to state the SMTP-Server as mail.moodle.org, determinte the correct Port for the smtpsecure option and be able to connect without the need to manually attach the Port to the SMTP-Server (mail.moodle.org:465) - though it is still possible and has priority over the code in the above patch.
With this patch mail.moodle.org:465 will work (ofcourse for implicit TLS [called SSL in the UI]) but also mail.moodle.org, if SSL is selected.
mail.moodle.org:466 will not work, even if the smptsecure type is set to SSL - therefore the given port has priority over the above code.
As an Administrator, this change is a more error prune way of handling this situation, since the port must not bet set explicitelly for a successfull TLS connection, but can still be changed if the SMTP Server is listening on another port for implicit TLS.
It would also make sense to differentiate between implicit TLS (called SSL in the UI) and STARTTLS (called TLS in the UI), since STARTTLS is no longer recommended by the IETF (see RFC 8314) since 2018.