Debug v17. Add log to help debug/fix smtp email errors
This commit is contained in:
parent
0f9ac598e2
commit
88a67afe34
@ -992,7 +992,26 @@ class CMailFile
|
|||||||
$this->dump_mail();
|
$this->dump_mail();
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->smtps->getErrors();
|
if (! $result) {
|
||||||
|
$smtperrorcode = $this->smtps->lastretval; // SMTP error code
|
||||||
|
dol_syslog("CMailFile::sendfile: mail SMTP error code ".$smtperrorcode, LOG_WARNING);
|
||||||
|
|
||||||
|
if ($smtperrorcode == '421') { // Try later
|
||||||
|
// TODO Add a delay and try again
|
||||||
|
/*
|
||||||
|
dol_syslog("CMailFile::sendfile: Try later error, so we wait and we retry");
|
||||||
|
sleep(2);
|
||||||
|
|
||||||
|
$result = $this->smtps->sendMsg();
|
||||||
|
|
||||||
|
if (!empty($conf->global->MAIN_MAIL_DEBUG)) {
|
||||||
|
$this->dump_mail();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $this->smtps->getErrors(); // applicative error code (not SMTP error code)
|
||||||
if (empty($this->error) && empty($result)) {
|
if (empty($this->error) && empty($result)) {
|
||||||
dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG);
|
dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG);
|
||||||
$res = true;
|
$res = true;
|
||||||
@ -1262,7 +1281,11 @@ class CMailFile
|
|||||||
|
|
||||||
if (@is_writeable($dolibarr_main_data_root)) { // Avoid fatal error on fopen with open_basedir
|
if (@is_writeable($dolibarr_main_data_root)) { // Avoid fatal error on fopen with open_basedir
|
||||||
$srcfile = $dolibarr_main_data_root."/dolibarr_mail.log";
|
$srcfile = $dolibarr_main_data_root."/dolibarr_mail.log";
|
||||||
|
if (getDolGlobalString('MAIN_MAIL_DEBUG_ERR_WITH_DATE')) {
|
||||||
|
$destfile = $dolibarr_main_data_root."/dolibarr_mail.".dol_print_date(dol_now(), 'dayhourlog', 'gmt').".err";
|
||||||
|
} else {
|
||||||
$destfile = $dolibarr_main_data_root."/dolibarr_mail.err";
|
$destfile = $dolibarr_main_data_root."/dolibarr_mail.err";
|
||||||
|
}
|
||||||
|
|
||||||
dol_move($srcfile, $destfile, 0, 1, 0, 0);
|
dol_move($srcfile, $destfile, 0, 1, 0, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -228,6 +228,7 @@ class SMTPs
|
|||||||
|
|
||||||
// @CHANGE LDR
|
// @CHANGE LDR
|
||||||
public $log = '';
|
public $log = '';
|
||||||
|
public $lastretval = '';
|
||||||
private $_errorsTo = '';
|
private $_errorsTo = '';
|
||||||
private $_deliveryReceipt = 0;
|
private $_deliveryReceipt = 0;
|
||||||
private $_trackId = '';
|
private $_trackId = '';
|
||||||
@ -670,10 +671,11 @@ class SMTPs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send the HELO message to the SMTP server
|
||||||
$_retVal = $this->socket_send_str('HELO '.$hosth, '250');
|
$_retVal = $this->socket_send_str('HELO '.$hosth, '250');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Well, did we get to the server?
|
// Well, did we get the server answer with correct code ?
|
||||||
if ($_retVal) {
|
if ($_retVal) {
|
||||||
// From this point onward most server response codes should be 250
|
// From this point onward most server response codes should be 250
|
||||||
// Specify who the mail is from....
|
// Specify who the mail is from....
|
||||||
@ -716,8 +718,11 @@ class SMTPs
|
|||||||
|
|
||||||
// Now tell the server we are done and close the socket...
|
// Now tell the server we are done and close the socket...
|
||||||
fputs($this->socket, 'QUIT');
|
fputs($this->socket, 'QUIT');
|
||||||
fclose($this->socket);
|
} else {
|
||||||
|
// We got code $this->lastretval
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fclose($this->socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $_retVal;
|
return $_retVal;
|
||||||
@ -1870,7 +1875,9 @@ class SMTPs
|
|||||||
* using SMTP Extensions
|
* using SMTP Extensions
|
||||||
*
|
*
|
||||||
* @param resource $socket Socket handler
|
* @param resource $socket Socket handler
|
||||||
* @param string $response Response. Example: "550 5.7.1 https://support.google.com/a/answer/6140680#invalidcred j21sm814390wre.3"
|
* @param string $response Expected response ('250', ...). Example of response we can get:
|
||||||
|
* "421 4.7.0 Try again later, closing connection. (EHLO) nb21-20020a1709071c9500b0093d0d964affsm869534ejc.73 - gsmtp"
|
||||||
|
* "550 5.7.1 https://support.google.com/a/answer/6140680#invalidcred j21sm814390wre.3"
|
||||||
* @return boolean True or false
|
* @return boolean True or false
|
||||||
*/
|
*/
|
||||||
public function server_parse($socket, $response)
|
public function server_parse($socket, $response)
|
||||||
@ -1897,6 +1904,8 @@ class SMTPs
|
|||||||
$limit++;
|
$limit++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->lastretval = substr($server_response, 0, 3);
|
||||||
|
|
||||||
if (!(substr($server_response, 0, 3) == $response)) {
|
if (!(substr($server_response, 0, 3) == $response)) {
|
||||||
$this->_setErr(120, "Ran into problems sending Mail.\r\nResponse: ".$server_response);
|
$this->_setErr(120, "Ran into problems sending Mail.\r\nResponse: ".$server_response);
|
||||||
$_retVal = false;
|
$_retVal = false;
|
||||||
@ -1910,7 +1919,7 @@ class SMTPs
|
|||||||
* Send str
|
* Send str
|
||||||
*
|
*
|
||||||
* @param string $_strSend String to send
|
* @param string $_strSend String to send
|
||||||
* @param string $_returnCode Return code
|
* @param string $_returnCode Expected return code
|
||||||
* @param string $CRLF CRLF
|
* @param string $CRLF CRLF
|
||||||
* @return boolean|null True or false
|
* @return boolean|null True or false
|
||||||
*/
|
*/
|
||||||
@ -1928,6 +1937,8 @@ class SMTPs
|
|||||||
if ($_returnCode) {
|
if ($_returnCode) {
|
||||||
return $this->server_parse($this->socket, $_returnCode);
|
return $this->server_parse($this->socket, $_returnCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// =============================================================
|
// =============================================================
|
||||||
@ -1949,7 +1960,7 @@ class SMTPs
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns errors codes and messages for Class
|
* Returns applicative errors codes and messages for Class (not the SMTP error code)
|
||||||
*
|
*
|
||||||
* @return string $_errMsg Error Message
|
* @return string $_errMsg Error Message
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user