Bug 2458: Si on envoie un email depuis Linux ,

le return-path doit être spécifié
This commit is contained in:
sparkyx 2026-04-01 17:17:09 +02:00
parent 5334bec89d
commit d444937bcc
5 changed files with 52 additions and 11 deletions

View file

@ -42,10 +42,7 @@ class Sendmail extends Sendmail_Core
{ {
if ( $this->can_send() == false ) throw new Exception(_('Email non envoyé'),EMAIL_LIMIT); if ( $this->can_send() == false ) throw new Exception(_('Email non envoyé'),EMAIL_LIMIT);
if (!mail($this->mailto, $this->subject, $this->content,$this->header)) parent::send();
{
throw new Exception('send failed');
}
// Increment email amount // Increment email amount
$repo =new Database(); $repo =new Database();
$date=date('Ymd'); $date=date('Ymd');
@ -167,7 +164,7 @@ class Sendmail extends Sendmail_Core
array(1,$p_dossier,$p_date)); array(1,$p_dossier,$p_date));
return; return;
} else { } else {
// update + sp_emaoun_email // update + amount of sent emails
$p_repo->exec_sql("update dossier_sent_email set de_sent_email=de_sent_email+1 where dos_id=$1 and de_date=$2", $p_repo->exec_sql("update dossier_sent_email set de_sent_email=de_sent_email+1 where dos_id=$1 and de_date=$2",
array($p_dossier,$p_date)); array($p_dossier,$p_date));
} }

View file

@ -97,4 +97,8 @@ define ("DEBUGNOALYSS",0);
// change NOALYSS_URL with your URL , // change NOALYSS_URL with your URL ,
// with NGINX it is needed to set the NOALYSS_URL , it is the default URL of // with NGINX it is needed to set the NOALYSS_URL , it is the default URL of
// your installation, example with https://demo.noalyss.eu // your installation, example with https://demo.noalyss.eu
// define ("NOALYSS_URL","https://demo.noalyss.eu"); // define ("NOALYSS_URL","https://demo.noalyss.eu");
// For POSTFIX, when sending email from NOALYSS via sendmail an extra parameter is needed
// for the Return-Path, the [FROM] will be replaced by the Sendmail_Core->from value
//define("MAIL_EXTRA_PARAM","-f [FROM]")

View file

@ -452,7 +452,9 @@ function noalyss_class_autoloader($class)
} }
} }
if ( ! defined("MAIL_EXTRA_PARAM")) {
define("MAIL_EXTRA_PARAM","-f [FROM]");
}
spl_autoload_register('\noalyss_class_autoloader', true); spl_autoload_register('\noalyss_class_autoloader', true);
require_once NOALYSS_BASE.'/vendor/autoload.php'; require_once NOALYSS_BASE.'/vendor/autoload.php';

View file

@ -306,6 +306,13 @@ function display_file_config($p_array, $from_setup = 1, $p_os = 1)
// your installation, example with https://demo.noalyss.eu $a // your installation, example with https://demo.noalyss.eu $a
// define ("NOALYSS_URL","https://demo.noalyss.eu"); $a // define ("NOALYSS_URL","https://demo.noalyss.eu"); $a
EOF; EOF;
echo <<<EOF
// $a
// $a
// For POSTFIX, when sending email from NOALYSS via sendmail an extra parameter is needed $a
// for the Return-Path, the [FROM] will be replaced by the email of the sender (Sendmail_Core->from value)$a
//define("MAIL_EXTRA_PARAM","-f [FROM]") $a
EOF;
} }
/*! /*!
* \brief create the config file * \brief create the config file

View file

@ -46,11 +46,39 @@ class Sendmail_Core
protected $content; protected $content;
protected $header; protected $header;
protected $format; protected $format;
protected $supplemental_header; //!< $supplemental_header(string) supplemental header to add
protected $supplemental_param; //!< $supplemental_param (string) 5th parameter for mail()
// for postfix, it should be "-f {$this->from}" for the Return-Path
function __construct() function __construct()
{ {
$this->format='PLAIN'; $this->format='PLAIN';
$this->supplemental_header="";
$this->supplemental_param=MAIL_EXTRA_PARAM;
} }
public function getSupplemental_param()
{
return $this->supplemental_param;
}
public function setSupplemental_param($supplemental_param)
{
$this->supplemental_param = $supplemental_param;
return $this;
}
public function getSupplemental_header()
{
return $this->supplemental_header;
}
public function setSupplemental_header($supplemental_header)
{
$this->supplemental_header = $supplemental_header;
return $this;
}
public function get_format() { public function get_format() {
return $this->format; return $this->format;
} }
@ -137,7 +165,7 @@ class Sendmail_Core
*/ */
function add_supplemental_header() function add_supplemental_header()
{ {
return ''; return $this->supplemental_header;
} }
/** /**
*@brief create the message before sending *@brief create the message before sending
@ -156,6 +184,7 @@ class Sendmail_Core
// main header (multipart mandatory) // main header (multipart mandatory)
$this->header = "From: " . $this->from . $eol; $this->header = "From: " . $this->from . $eol;
$this->header .= "Reply-To: " . $this->from . $eol;
$this->header .= "MIME-Version: 1.0" . $eol; $this->header .= "MIME-Version: 1.0" . $eol;
$this->header .= $this->add_supplemental_header(); $this->header .= $this->add_supplemental_header();
if ($this->format == 'PLAIN') if ($this->format == 'PLAIN')
@ -232,6 +261,7 @@ eof;
if ( empty ($this->afile) ) $this->content.=$eol; if ( empty ($this->afile) ) $this->content.=$eol;
$this->content .= "--" . $separator . "--"; $this->content .= "--" . $separator . "--";
$this->supplemental_param= str_replace("[FROM]", $this->from, $this->supplemental_param);
} }
/** /**
@ -246,8 +276,9 @@ eof;
} catch (Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
$encoded_subject = mb_encode_mimeheader( $this->subject, 'UTF-8', 'B');
if (!mail($this->mailto, $this->subject, $this->content,$this->header))
if (!mail($this->mailto,$encoded_subject, $this->content,$this->header,$this->supplemental_param))
{ {
throw new Exception('send failed'); throw new Exception('send failed');
} }