From 28c4dd88a26dadce160d1d19952298cd5a0c2a99 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 31 Aug 2022 14:02:09 +0200 Subject: [PATCH] FIX use correct smtp setup for the check_server_port() test --- htdocs/core/class/CMailFile.class.php | 38 ++++++++++++++++----------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index 42dcd1d493b..f9157a6a3c2 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -156,7 +156,7 @@ class CMailFile * @param string $errors_to Email for errors-to * @param string $css Css option * @param string $trackid Tracking string (contains type and id of related element) - * @param string $moreinheader More in header. $moreinheader must contains the "\r\n" (TODO not supported for other MAIL_SEND_MODE different than 'phpmail' and 'smtps' for the moment) + * @param string $moreinheader More in header. $moreinheader must contains the "\r\n" (TODO not supported for other MAIL_SEND_MODE different than 'mail' and 'smtps' for the moment) * @param string $sendcontext 'standard', 'emailing', ... (used to define which sending mode and parameters to use) * @param string $replyto Reply-to email (will be set to same value than From by default if not provided) */ @@ -173,12 +173,11 @@ class CMailFile $this->sendcontext = $sendcontext; - // Define this->sendmode + // Define this->sendmode ('mail', 'smtps', 'siwftmailer', ...) according to $sendcontext ('standard', 'emailing', 'ticket') $this->sendmode = ''; if (!empty($this->sendcontext)) { $smtpContextKey = strtoupper($this->sendcontext); - $keyForSMTPSendMode = 'MAIN_MAIL_SENDMODE_'.$smtpContextKey; - $smtpContextSendMode = empty($conf->global->{$keyForSMTPSendMode}) ? '' : $conf->global->{$keyForSMTPSendMode}; + $smtpContextSendMode = getDolGlobalString('MAIN_MAIL_SENDMODE_'.$smtpContextKey); if (!empty($smtpContextSendMode) && $smtpContextSendMode != 'default') { $this->sendmode = $smtpContextSendMode; } @@ -329,8 +328,7 @@ class CMailFile $keyforsslseflsigned = 'MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED'; if (!empty($this->sendcontext)) { $smtpContextKey = strtoupper($this->sendcontext); - $keyForSMTPSendMode = 'MAIN_MAIL_SENDMODE_'.$smtpContextKey; - $smtpContextSendMode = empty($conf->global->{$keyForSMTPSendMode}) ? '' : $conf->global->{$keyForSMTPSendMode}; + $smtpContextSendMode = getDolGlobalString('MAIN_MAIL_SENDMODE_'.$smtpContextKey); if (!empty($smtpContextSendMode) && $smtpContextSendMode != 'default') { $keyforsslseflsigned = 'MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_'.$smtpContextKey; } @@ -701,8 +699,7 @@ class CMailFile $keyforsslseflsigned = 'MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED'; if (!empty($this->sendcontext)) { $smtpContextKey = strtoupper($this->sendcontext); - $keyForSMTPSendMode = 'MAIN_MAIL_SENDMODE_'.$smtpContextKey; - $smtpContextSendMode = empty($conf->global->{$keyForSMTPSendMode}) ? '' : $conf->global->{$keyForSMTPSendMode}; + $smtpContextSendMode = getDolGlobalString('MAIN_MAIL_SENDMODE_'.$smtpContextKey); if (!empty($smtpContextSendMode) && $smtpContextSendMode != 'default') { $keyforsmtpserver = 'MAIN_MAIL_SMTP_SERVER_'.$smtpContextKey; $keyforsmtpport = 'MAIN_MAIL_SMTP_PORT_'.$smtpContextKey; @@ -1537,15 +1534,26 @@ class CMailFile $keyforsmtpport = 'MAIN_MAIL_SMTP_PORT'; $keyforsmtpid = 'MAIN_MAIL_SMTPS_ID'; $keyforsmtppw = 'MAIN_MAIL_SMTPS_PW'; + $keyforsmtpauthtype = 'MAIN_MAIL_SMTPS_AUTH_TYPE'; + $keyforsmtpoauthservice = 'MAIN_MAIL_SMTPS_OAUTH_SERVICE'; $keyfortls = 'MAIN_MAIL_EMAIL_TLS'; $keyforstarttls = 'MAIN_MAIL_EMAIL_STARTTLS'; - if ($this->sendcontext == 'emailing' && !empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default') { - $keyforsmtpserver = 'MAIN_MAIL_SMTP_SERVER_EMAILING'; - $keyforsmtpport = 'MAIN_MAIL_SMTP_PORT_EMAILING'; - $keyforsmtpid = 'MAIN_MAIL_SMTPS_ID_EMAILING'; - $keyforsmtppw = 'MAIN_MAIL_SMTPS_PW_EMAILING'; - $keyfortls = 'MAIN_MAIL_EMAIL_TLS_EMAILING'; - $keyforstarttls = 'MAIN_MAIL_EMAIL_STARTTLS_EMAILING'; + $keyforsslseflsigned = 'MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED'; + + if (!empty($this->sendcontext)) { + $smtpContextKey = strtoupper($this->sendcontext); + $smtpContextSendMode = getDolGlobalString('MAIN_MAIL_SENDMODE_'.$smtpContextKey); + if (!empty($smtpContextSendMode) && $smtpContextSendMode != 'default') { + $keyforsmtpserver = 'MAIN_MAIL_SMTP_SERVER_'.$smtpContextKey; + $keyforsmtpport = 'MAIN_MAIL_SMTP_PORT_'.$smtpContextKey; + $keyforsmtpid = 'MAIN_MAIL_SMTPS_ID_'.$smtpContextKey; + $keyforsmtppw = 'MAIN_MAIL_SMTPS_PW_'.$smtpContextKey; + $keyforsmtpauthtype = 'MAIN_MAIL_SMTPS_AUTH_TYPE_'.$smtpContextKey; + $keyforsmtpoauthservice = 'MAIN_MAIL_SMTPS_OAUTH_SERVICE_'.$smtpContextKey; + $keyfortls = 'MAIN_MAIL_EMAIL_TLS_'.$smtpContextKey; + $keyforstarttls = 'MAIN_MAIL_EMAIL_STARTTLS_'.$smtpContextKey; + $keyforsslseflsigned = 'MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_'.$smtpContextKey; + } } // If we use SSL/TLS