53 private $_smtpsHost =
'localhost';
61 private $_smtpsPort = 25;
67 private $_smtpsID =
null;
73 private $_smtpsPW =
null;
78 private $_smtpsToken =
null;
83 private $_msgId =
null;
88 private $_smtpsAuthType =
'';
94 private $_msgFrom =
null;
100 private $_msgReplyTo =
null;
105 private $_msgInReplyTo =
null;
110 private $_msgReferences =
null;
117 private $_msgRecipients =
null;
122 private $_msgSubject =
null;
129 private $_msgContent = array();
134 private $_msgXheader = array();
141 private $_smtpsCharSet =
'iso-8859-1';
148 private $_msgSensitivity = 0;
153 private $_arySensitivity = array(
false,
156 'Company Confidential');
162 private $_msgPriority = 3;
167 private $_aryPriority = array(
'Bulk',
178 private $_smtpsTransEncodeType = 0;
183 private $_smtpsTransEncodeTypes = array(
'7bit',
196 private $_smtpsTransEncode =
'7bit';
201 private $_smtpsBoundary =
null;
206 private $_smtpsRelatedBoundary =
null;
211 private $_smtpsAlternativeBoundary =
null;
221 private $_transportType = 0;
227 private $_mailPath =
'/usr/lib/sendmail';
232 private $_smtpTimeout = 10;
237 private $_smtpMD5 =
false;
242 private $_smtpsErrors = array();
251 private $_log_level = 0;
256 private $_debug =
false;
267 public $lastretval =
'';
287 private $_errorsTo = array();
291 private $_deliveryReceipt = 0;
295 private $_trackId =
'';
299 private $_moreinheader =
'';
304 private $_options = array();
315 $this->_msgId = $_msgId;
326 $this->_options = $_options;
337 $this->_deliveryReceipt = $_val;
347 return $this->_deliveryReceipt;
358 $this->_smtpTimeout = $timeout;
368 return $this->_smtpTimeout;
379 $this->_trackId = $_val;
390 $this->_moreinheader = $_val;
400 return $this->_trackId;
410 return $this->_moreinheader;
436 if ($_part ===
true || !array_key_exists($_part, $this->_errorsTo)) {
437 $_retValue = $this->_errorsTo;
439 $_retValue = $this->_errorsTo[$_part];
453 $this->_debug = $_vDebug;
464 $_aryToList = $this->
getTo();
483 $usetls = preg_match(
'@tls://@i', $host);
485 $host = preg_replace(
'@tcp://@i',
'', $host);
486 $host = preg_replace(
'@ssl://@i',
'', $host);
487 $host = preg_replace(
'@tls://@i',
'', $host);
490 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
492 if ((!
is_ip($host)) && ((gethostbyname($host)) == $host)) {
493 $this->
_setErr(99, $host.
' is either offline or is an invalid host name.');
496 if (function_exists(
'stream_socket_client') && !empty($this->_options)) {
497 $socket_context = stream_context_create($this->_options);
498 $this->socket = @stream_socket_client(
499 preg_replace(
'@tls://@i',
'', $this->
getHost()).
504 STREAM_CLIENT_CONNECT,
508 $this->socket = @fsockopen(
509 preg_replace(
'@tls://@i',
'', $this->
getHost()),
518 if (is_resource($this->socket)) {
523 if (function_exists(
'stream_set_timeout')) {
524 stream_set_timeout($this->socket, $this->_smtpTimeout, 0);
528 if ($_retVal = $this->
server_parse($this->socket,
"220")) {
529 $_retVal = $this->socket;
534 if (empty($this->errstr)) {
535 $this->errstr =
'Failed to connect with stream_context_create or fsockopen host='.$this->getHost().
' port='.$this->
getPort();
537 $this->
_setErr($this->errno, $this->errstr);
555 require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
560 $usetls = preg_match(
'@tls://@i', $host);
562 $host = preg_replace(
'@tcp://@i',
'', $host);
563 $host = preg_replace(
'@ssl://@i',
'', $host);
564 $host = preg_replace(
'@tls://@i',
'', $host);
567 $host =
'tls://'.$host;
579 $hosth = (string) $this->
getFrom(
'addr');
580 $hosth = preg_replace(
'/^.*</',
'', $hosth);
581 $hosth = preg_replace(
'/>.*$/',
'', $hosth);
582 $hosth = preg_replace(
'/.*@/',
'', $hosth);
645 $this->
_setErr(131,
'STARTTLS connection is not supported.');
656 $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT;
657 if (defined(
'STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) {
658 $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
659 $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
662 if (!stream_socket_enable_crypto($this->socket,
true, $crypto_method)) {
663 $this->
_setErr(132,
'STARTTLS connection failed.');
669 $this->
_setErr(126,
'"'.$hosth.
'" does not support authenticated connections or temporary error. Error after 2nd sending EHLO '.$hosth.
' : '.$this->lastretval);
681 $authtype = $this->_smtpsAuthType ? $this->_smtpsAuthType :
getDolGlobalString(
'MAIN_MAIL_SMTPS_AUTH_TYPE',
'LOGIN');
694 $this->
_setErr(130,
'Error when asking for AUTH PLAIN');
697 $_retVal = $this->
socket_send_str(base64_encode(
"\0".$this->_smtpsID.
"\0".$this->_smtpsPW),
'235');
702 $user = $this->_smtpsID;
703 $token = $this->_smtpsToken;
704 $initRes =
"user=".$user.
"\001auth=Bearer ".$token.
"\001\001";
705 $_retVal = $this->
socket_send_str(
'AUTH XOAUTH2 '.base64_encode($initRes),
'235');
707 $this->
_setErr(130,
'Error when asking for AUTH XOAUTH2');
714 $this->
_setErr(130,
'Error when asking for AUTH LOGIN');
717 $this->
socket_send_str(base64_encode((
string) $this->_smtpsID),
'334');
720 $_retVal = $this->
socket_send_str(base64_encode((
string) $this->_smtpsPW),
'235');
725 $this->
_setErr(130,
'Invalid Authentication Credentials.');
728 $this->
_setErr(126,
'"'.$host.
'" refused the EHLO command. Error after sending EHLO '.$hosth.
' : '.$this->lastretval);
741 require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
749 if (!empty($this->_smtpsID) && (!empty($this->_smtpsPW) || !empty($this->_smtpsToken))) {
752 } elseif (preg_match(
'@tls://@i', $this->
getHost())) {
759 $usetls = preg_match(
'@tls://@i', $host);
761 $host = preg_replace(
'@tcp://@i',
'', $host);
762 $host = preg_replace(
'@ssl://@i',
'', $host);
763 $host = preg_replace(
'@tls://@i',
'', $host);
766 $host =
'tls://'.$host;
778 $hosth = (string) $this->
getFrom(
'addr');
779 $hosth = preg_replace(
'/^.*</',
'', $hosth);
780 $hosth = preg_replace(
'/>.*$/',
'', $hosth);
781 $hosth = preg_replace(
'/.*@/',
'', $hosth);
799 if (!$resultmailfrom) {
800 fclose($this->socket);
820 fclose($this->socket);
830 fclose($this->socket);
836 $data = $this->
getHeader().$this->getBodyContent();
839 $data = preg_replace(
'/^\./m',
'..', $data);
848 fclose($this->socket);
893 if (!empty($_strConfigPath)) {
896 if (!@include $_strConfigPath) {
897 $this->
_setErr(110,
'"'.$_strConfigPath.
'" is not a valid path.');
904 if ($_host = ini_get(
'SMTPs')) {
908 if ($_port = ini_get(
'smtp_port')) {
912 if ($_from = ini_get(
'sendmail_from')) {
932 if ((is_numeric($_type)) && (($_type >= 0) && ($_type <= 3))) {
933 $this->_transportType = $_type;
947 return $this->_transportType;
975 $this->_smtpsHost = $_strHost;
987 return $this->_smtpsHost;
1000 if ((is_numeric($_intPort)) &&
1001 (($_intPort >= 1) && ($_intPort <= 65536))) {
1002 $this->_smtpsPort = (int) $_intPort;
1014 return (
int) $this->_smtpsPort;
1025 $this->_smtpsID = $_strID;
1035 return $this->_smtpsID;
1046 $this->_smtpsPW = $_strPW;
1056 return $this->_smtpsPW;
1067 $this->_smtpsToken = $_strToken;
1078 $this->_smtpsAuthType = (string) $_strAuthType;
1088 return $this->_smtpsToken;
1101 $this->_smtpsCharSet = $_strCharSet;
1112 return $this->_smtpsCharSet;
1132 if (array_search($_strTransEncode, $this->_smtpsTransEncodeTypes)) {
1133 $this->_smtpsTransEncode = $_strTransEncode;
1144 return $this->_smtpsTransEncode;
1164 if (array_search($_strTransEncodeType, $this->_smtpsTransEncodeTypes)) {
1165 $this->_smtpsTransEncodeType = $_strTransEncodeType;
1176 return $this->_smtpsTransEncodeTypes[$this->_smtpsTransEncodeType];
1205 if ($_part ===
true || $this->_msgFrom ===
null) {
1206 $_retValue = $this->_msgFrom;
1208 $_retValue = $this->_msgFrom[$_part];
1223 $this->_msgReplyTo = $this->
_strip_email($_strReplyTo);
1237 if ($_part ===
true) {
1238 $_retValue = $this->_msgReplyTo;
1240 $_retValue = $this->_msgReplyTo[$_part];
1254 if ($_strInReplyTo) {
1255 $this->_msgInReplyTo = $_strInReplyTo;
1266 $_retValue = $this->_msgInReplyTo;
1279 if ($_strReferences) {
1280 $this->_msgReferences = $_strReferences;
1291 $_retValue = $this->_msgReferences;
1308 $aryHost = $this->_msgRecipients;
1311 if (!empty($_addrList)) {
1313 if (is_string($_addrList)) {
1315 if (strstr($_addrList,
',')) {
1317 $_addrList = explode(
',', $_addrList);
1320 $_addrList = array($_addrList);
1325 foreach ($_addrList as $_strAddr) {
1327 $_strAddr = str_replace(
'>',
'', $_strAddr);
1331 $_tmpaddr = explode(
'<', $_strAddr);
1334 if (count($_tmpaddr) == 2) {
1335 $_tmpHost = explode(
'@', $_tmpaddr[1]);
1336 $_tmpaddr[0] = trim($_tmpaddr[0],
' ">');
1337 $aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] = $_tmpaddr[0];
1341 $_strAddr = str_replace(
'<',
'', $_strAddr);
1343 $_tmpHost = explode(
'@', $_strAddr);
1344 $_tmpHost[0] = trim($_tmpHost[0]);
1345 $_tmpHost[1] = trim($_tmpHost[1]);
1347 $aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] =
'';
1352 $this->_msgRecipients = $aryHost;
1375 $_aryEmail = array();
1377 $_aryEmail[
'org'] = $_strAddr;
1380 $_strAddr = strtolower($_strAddr);
1383 $_strAddr = trim($_strAddr,
' ">');
1386 $_tmpAry = explode(
'<', $_strAddr);
1389 if (count($_tmpAry) == 2) {
1392 $_aryEmail[
'real'] = trim($_tmpAry[0],
' ">');
1395 $_aryEmail[
'addr'] = $_tmpAry[1];
1397 $_aryEmail[
'addr'] = $_tmpAry[0];
1401 $_tmpHost = explode(
'@', $_aryEmail[
'addr']);
1402 $_aryEmail[
'user'] = $_tmpHost[0];
1403 $_aryEmail[
'host'] = $_tmpHost[1];
1406 $_aryEmail[
'addr'] =
'<'.$_aryEmail[
'addr'].
'>';
1425 $_RCPT_list = array();
1428 foreach ($this->_msgRecipients as $_host => $_list) {
1429 foreach ($_list as $_subList) {
1430 foreach ($_subList as $_name => $_addr) {
1432 $_RCPT_list[] = $_name.
'@'.$_host;
1453 if ($this->_msgRecipients) {
1454 $_RCPT_list = array();
1456 foreach ($this->_msgRecipients as $_host => $_list) {
1457 if (!empty($this->_msgRecipients[$_host][$_which])) {
1458 foreach ($this->_msgRecipients[$_host][$_which] as $_addr => $_realName) {
1460 $_realName =
'"'.$_realName.
'"';
1461 $_RCPT_list[] = $_realName.
' <'.$_addr.
'@'.$_host.
'>';
1463 $_RCPT_list[] = $_addr.
'@'.$_host;
1469 return implode(
', ', $_RCPT_list);
1471 $this->
_setErr(101,
'No eMail Address for message to be sent to.');
1475 $this->
_setErr(102,
'eMail type not defined.');
1558 $this->_msgSubject = $_strSubject;
1569 return $this->_msgSubject;
1579 $_header =
'From: '.$this->getFrom(
'org').
"\r\n"
1580 .
'To: '.$this->getTo().
"\r\n";
1582 if ($this->
getCC()) {
1583 $_header .=
'Cc: '.$this->getCC().
"\r\n";
1597 $host = dol_getprefix(
'email');
1599 $_header .=
'Subject: '.$this->getSubject().
"\r\n";
1600 $_header .=
'Date: '.date(
"r").
"\r\n";
1604 $_header .=
'Message-ID: <'.(empty($this->_msgId) ? uniqid().
'.SMTPs-dolibarr-'.$trackid.
'@'.$host : $this->_msgId).
">\r\n";
1605 $_header .=
'X-Dolibarr-TRACKID: '.$trackid.
'@'.$host.
"\r\n";
1607 $_header .=
'Message-ID: <'.(empty($this->_msgId) ? uniqid().
'.SMTPs@'.$host : $this->_msgId).
">\r\n";
1609 if (!empty($_SERVER[
'REMOTE_ADDR'])) {
1610 $_header .=
"X-RemoteAddr: ".$_SERVER[
'REMOTE_ADDR'].
"\r\n";
1614 $_header .= preg_replace(
'/(?<!\r)\n/',
"\r\n", $this->
getMoreInHeader());
1618 $_header .=
'Sensitivity: '.$this->getSensitivity().
"\r\n";
1621 if ($this->_msgPriority != 3) {
1628 $_header .=
'Disposition-Notification-To: '.$this->getFrom(
'addr').
"\r\n";
1631 $_header .=
'Errors-To: '.$this->getErrorsTo(
'addr').
"\r\n";
1634 $_header .=
"Reply-To: ".$this->getReplyTo(
'addr').
"\r\n";
1637 $_header .=
'X-Mailer: Dolibarr version '.DOL_VERSION.
' (using SMTPs Mailer)'.
"\r\n";
1638 $_header .=
'X-Dolibarr-Option: '.(getDolGlobalString(
'MAIN_MAIL_USE_MULTI_PART') ?
'MAIN_MAIL_USE_MULTI_PART' :
'No MAIN_MAIL_USE_MULTI_PART').
"\r\n";
1639 $_header .=
'Mime-Version: 1.0'.
"\r\n";
1643 $_header .=
"In-Reply-To: ".$this->getInReplyTo().
"\r\n";
1649 $_header .=
"References: ".implode(
' ', $references).
"\r\n";
1666 if ($strType ==
'html') {
1667 $strMimeType =
'text/html';
1669 $strMimeType =
'text/plain';
1673 $strContent = preg_replace(
"/(?<!\r)\n/si",
"\r\n", $strContent);
1675 $strContentAltText =
'';
1676 if ($strType ==
'html') {
1678 $strContentAltText = preg_replace(
'/<head><title>.*<\/style><\/head>/',
'', $strContent);
1679 $strContentAltText = preg_replace(
"/<br\s*[^>]*>/",
" ", $strContentAltText);
1680 $strContentAltText = html_entity_decode(strip_tags($strContentAltText));
1681 $strContentAltText = trim(wordwrap($strContentAltText, 75,
"\r\n"));
1686 $strContent = rtrim(wordwrap($strContent, 75,
"\r\n"));
1688 $this->_msgContent[$strType] = array();
1690 $this->_msgContent[$strType][
'mimeType'] = $strMimeType;
1691 $this->_msgContent[$strType][
'data'] = $strContent;
1692 $this->_msgContent[$strType][
'dataText'] = $strContentAltText;
1695 $this->_msgContent[$strType][
'md5'] =
dol_hash($strContent,
'3');
1713 $_types = array_keys($this->_msgContent);
1716 $keyCount = count($_types);
1719 if ($keyCount === 0) {
1720 die(
"Sorry, no content");
1723 $_msgData = $this->_msgContent;
1724 $_msgData = $_msgData[$_types[0]];
1726 $content =
'Content-Type: '.$_msgData[
'mimeType'].
'; charset="'.$this->
getCharSet().
'"'.
"\r\n"
1727 .
'Content-Transfer-Encoding: '.$this->_getTextTransferEncoding($_msgData[
'data']).
"\r\n"
1728 .
'Content-Disposition: inline'.
"\r\n"
1729 .
'Content-Description: Message'.
"\r\n";
1732 $content .=
'Content-MD5: '.$_msgData[
'md5'].
"\r\n";
1736 . $_msgData[
'data'].
"\r\n";
1744 $content =
'Content-Type: multipart/mixed; boundary="'.$this->_getBoundary(
'mixed').
'"'.
"\r\n";
1748 $content .=
"Content-Transfer-Encoding: 8bit\r\n";
1751 $content .=
"--".$this->_getBoundary(
'mixed').
"\r\n";
1753 if (array_key_exists(
'image', $this->_msgContent)) {
1754 $content .=
'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary(
'alternative').
'"'.
"\r\n";
1756 $content .=
"--".$this->_getBoundary(
'alternative').
"\r\n";
1764 foreach ($this->_msgContent as $type => $_content) {
1765 if ($type ==
'attachment') {
1767 foreach ($_content as $_file => $_data) {
1768 $content .=
"--".$this->_getBoundary(
'mixed').
"\r\n"
1769 .
'Content-Disposition: attachment; filename="'.$_data[
'fileName'].
'"'.
"\r\n"
1770 .
'Content-Type: '.$_data[
'mimeType'].
'; name="'.$_data[
'fileName'].
'"'.
"\r\n"
1771 .
'Content-Transfer-Encoding: base64'.
"\r\n"
1772 .
'Content-Description: '.$_data[
'fileName'].
"\r\n";
1773 if (!empty($_data[
'cid'])) {
1774 $content .=
"X-Attachment-Id: ".$_data[
'cid'].
"\r\n";
1775 $content .=
"Content-ID: <".$_data[
'cid'].
">\r\n";
1778 $content .=
'Content-MD5: '.$_data[
'md5'].
"\r\n";
1781 $content .=
"\r\n".$_data[
'data'].
"\r\n\r\n";
1783 } elseif ($type ==
'image') {
1786 foreach ($_content as $_image => $_data) {
1787 $content .=
"--".$this->_getBoundary(
'related').
"\r\n";
1789 $content .=
'Content-Type: '.$_data[
'mimeType'].
'; name="'.$_data[
'imageName'].
'"'.
"\r\n"
1790 .
'Content-Transfer-Encoding: base64'.
"\r\n"
1791 .
'Content-Disposition: inline; filename="'.$_data[
'imageName'].
'"'.
"\r\n"
1792 .
'Content-ID: <'.$_data[
'cid'].
'> '.
"\r\n";
1795 $content .=
'Content-MD5: '.$_data[
'md5'].
"\r\n";
1799 . $_data[
'data'].
"\r\n";
1803 $content .=
"--".$this->_getBoundary(
'related').
"--\r\n";
1804 $content .=
"\r\n--".$this->_getBoundary(
'alternative').
"--\r\n";
1807 if (array_key_exists(
'image', $this->_msgContent)) {
1808 $content .=
"Content-Type: text/plain; charset=".$this->getCharSet().
"\r\n";
1809 $content .=
'Content-Transfer-Encoding: '.$this->_getTextTransferEncoding($_content[
'dataText'] ? $_content[
'dataText'] : strip_tags($_content[
'data'])).
"\r\n";
1810 $content .=
"\r\n".($_content[
'dataText'] ? $_content[
'dataText'] : strip_tags($_content[
'data'])).
"\r\n";
1811 $content .=
"--".$this->_getBoundary(
'alternative').
"\r\n";
1812 $content .=
'Content-Type: multipart/related; boundary="'.$this->_getBoundary(
'related').
'"'.
"\r\n";
1814 $content .=
"--".$this->_getBoundary(
'related').
"\r\n";
1817 if (!array_key_exists(
'image', $this->_msgContent) && $_content[
'dataText'] &&
getDolGlobalString(
'MAIN_MAIL_USE_MULTI_PART')) {
1819 $content .=
'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary(
'alternative').
'"'.
"\r\n";
1821 $content .=
"--".$this->_getBoundary(
'alternative').
"\r\n";
1823 $content .=
"Content-Type: text/plain; charset=".$this->getCharSet().
"\r\n";
1824 $content .=
'Content-Transfer-Encoding: '.$this->_getTextTransferEncoding($_content[
'dataText']).
"\r\n";
1825 $content .=
"\r\n".$_content[
'dataText'].
"\r\n";
1826 $content .=
"--".$this->_getBoundary(
'alternative').
"\r\n";
1829 $content .=
'Content-Type: '.$_content[
'mimeType'].
'; charset='.$this->
getCharSet();
1832 $content .=
'Content-Transfer-Encoding: '.$this->_getTextTransferEncoding($_content[
'data']).
"\r\n";
1835 $content .=
'Content-MD5: '.$_content[
'md5'].
"\r\n";
1838 $content .=
"\r\n".$_content[
'data'].
"\r\n";
1840 if (!array_key_exists(
'image', $this->_msgContent) && $_content[
'dataText'] &&
getDolGlobalString(
'MAIN_MAIL_USE_MULTI_PART')) {
1842 $content .=
"--".$this->_getBoundary(
'alternative').
"--\r\n";
1849 $content .=
"--".$this->_getBoundary(
'mixed').
'--'.
"\r\n";
1851 die(
"Sorry, no content");
1868 if (preg_match(
'/[^\x00-\x7F]/', $text)) {
1884 public function setAttachment($strContent, $strFileName =
'unknown', $strMimeType =
'unknown', $strCid =
'')
1887 $strContent = rtrim(chunk_split(base64_encode($strContent), 76,
"\r\n"));
1891 $attachmentkey = $strFileName.
'-'.
dol_hash($strContent,
'sha256');
1893 $this->_msgContent[
'attachment'][$attachmentkey][
'mimeType'] = $strMimeType;
1894 $this->_msgContent[
'attachment'][$attachmentkey][
'fileName'] = $strFileName;
1895 $this->_msgContent[
'attachment'][$attachmentkey][
'data'] = $strContent;
1896 $this->_msgContent[
'attachment'][$attachmentkey][
'cid'] = $strCid;
1899 $this->_msgContent[
'attachment'][$attachmentkey][
'md5'] =
dol_hash($strContent,
'3');
1917 public function setImageInline($strContent, $strImageName =
'unknown', $strMimeType =
'unknown', $strImageCid =
'unknown')
1920 $this->_msgContent[
'image'][$strImageName][
'mimeType'] = $strMimeType;
1921 $this->_msgContent[
'image'][$strImageName][
'imageName'] = $strImageName;
1922 $this->_msgContent[
'image'][$strImageName][
'data'] = $strContent;
1923 $this->_msgContent[
'image'][$strImageName][
'cid'] = $strImageCid;
1926 $this->_msgContent[
'image'][$strImageName][
'md5'] =
dol_hash($strContent,
'3');
1946 if ((is_numeric($_value)) &&
1947 (($_value >= 0) && ($_value <= 3))) {
1948 $this->_msgSensitivity = $_value;
1964 return $this->_arySensitivity[$this->_msgSensitivity];
1982 if ((is_numeric($_value)) &&
1983 (($_value >= 0) && ($_value <= 5))) {
1984 $this->_msgPriority = $_value;
2002 return 'Importance: '.$this->_aryPriority[$this->_msgPriority].
"\r\n"
2003 .
'Priority: '.$this->_aryPriority[$this->_msgPriority].
"\r\n"
2004 .
'X-Priority: '.$this->_msgPriority.
' ('.$this->_aryPriority[$this->_msgPriority].
')'.
"\r\n";
2015 $this->_smtpMD5 = $_flag;
2025 return $this->_smtpMD5;
2039 $this->_msgXheader[] = $strXdata;
2050 return $this->_msgXheader;
2060 $this->_smtpsBoundary =
"multipart_x.".time().
".x_boundary";
2061 $this->_smtpsRelatedBoundary =
'mul_'.dol_hash(uniqid(
"dolibarr2"),
'3');
2062 $this->_smtpsAlternativeBoundary =
'mul_'.dol_hash(uniqid(
"dolibarr3"),
'3');
2073 if ($type ==
'mixed') {
2074 return $this->_smtpsBoundary;
2075 } elseif ($type ==
'related') {
2076 return $this->_smtpsRelatedBoundary;
2077 } elseif ($type ==
'alternative') {
2078 return $this->_smtpsAlternativeBoundary;
2103 $server_response =
'';
2108 while (substr($server_response, 3, 1) !=
' ' && $limit < 100) {
2110 if (!($server_response = fgets($socket))) {
2111 $this->
_setErr(121,
"Couldn't get mail server response codes");
2115 $this->log .= $server_response;
2119 $this->lastretval = substr($server_response, 0, 3);
2121 if (!(substr($server_response, 0, 3) == $response)) {
2122 $this->
_setErr(120,
"Ran into problems sending Mail.\r\nResponse: ".$server_response);
2141 if ($this->_debug) {
2142 $this->log .= $_strSend;
2144 fwrite($this->socket, $_strSend.$CRLF);
2145 if ($this->_debug) {
2146 $this->log .=
' ('.$_returnCode.
')'.$CRLF;
2150 return $this->
server_parse($this->socket, $_returnCode);
2168 $this->_smtpsErrors[] = array(
2183 if (is_array($this->_smtpsErrors)) {
2184 foreach ($this->_smtpsErrors as $_err => $_info) {
2185 $_errMsg[] =
'Error ['.$_info[
'num'].
']: '.$_info[
'msg'];
2189 return implode(
"\n", $_errMsg);
global $dolibarr_main_url_root
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to construct and send SMTP compliant email, even to a secure SMTP server, regardless of platfor...
_getBoundary($type='mixed')
Retrieves the MIME message Boundary.
setConfig($_strConfigPath=null)
setConfig() is used to populate select class properties from either a user defined INI file or the sy...
sendMsg()
Now send the message.
getErrors()
Returns applicative errors codes and messages for Class (not the SMTP error code)
setCharSet($_strCharSet)
Character set used for current message Character set is defaulted to 'iso-8859-1';.
setSubject($_strSubject='')
Message Subject.
getPriority()
Message Content Priority Message Priority values:
setAuthType($_strAuthType)
Authentication method to use (the one of the send context)
setReferences($_strReferences)
Set References in the list of Msg-Id.
getMD5flag()
Gets flag which determines whether to calculate message MD5 checksum.
socket_send_str($_strSend, $_returnCode=null, $CRLF="\r\n")
Send str.
_strip_email($_strAddr)
Returns an array of the various parts of an email address This assumes a well formed address:
getTransEncodeType()
Retrieves the Content-Transfer-Encoding.
setTrackId($_val='')
Set trackid.
setToken($_strToken)
User token for OAUTH2.
setInReplyTo($_strInReplyTo)
Set References in the list of Msg-Id.
buildRCPTlist()
build RECIPIENT List, all addresses who will receive this message
getBodyContent()
Retrieves the Message Content.
_buildAddrList($_type, $_addrList)
Inserts given addresses into structured format.
getInReplyTo()
Retrieves the InReplyTo from which mail we reply to.
setOptions($_options=array())
Set options.
_server_connect()
Attempt a connection to mail server.
setBodyContent($strContent, $strType='plain')
Message Content.
server_parse($socket, $response)
This function has been modified as provided by SirSir to allow multiline responses when using SMTP Ex...
setTransportType($_type=0)
Determines the method inwhich the messages are to be sent.
getBCC()
Retrieves the BCC Address[es] inwhich to send mail to.
setAttachment($strContent, $strFileName='unknown', $strMimeType='unknown', $strCid='')
File attachments are added to the content array as sub-arrays, allowing for multiple attachments for ...
_setBoundary()
Generates Random string for MIME message Boundary.
getTo()
Retrieves the TO Address[es] inwhich to send mail to.
setPort($_intPort)
Defines the Port Number of the Mail Server to use The default is 25 This is used only with 'socket' b...
getID()
Retrieves the User Name for authentication on Mail Server.
setBCC($_strBCC)
BCC Address[es] inwhich to send mail to.
setReplyTo($_strReplyTo)
Reply-To Address from which mail will be the reply-to.
getToken()
Retrieves the User token for OAUTH2.
setSensitivity($_value=0)
Message Content Sensitivity Message Sensitivity values:
setCC($_strCC)
CC Address[es] inwhich to send mail to.
getSMTPTimeout()
Get socket timeout.
setTO($_addrTo)
TO Address[es] inwhich to send mail to.
setTransEncodeType($_strTransEncodeType)
Content-Transfer-Encoding, Defaulted to '0' [ZERO] This can be changed for 2byte characters sets Know...
get_email_list($_which=null)
Returns an array of addresses for a specific type; TO, CC or BCC.
setMD5flag($_flag=false)
Set flag which determines whether to calculate message MD5 checksum.
getCharSet()
Retrieves the Character set used for current message.
getCC()
Retrieves the CC Address[es] inwhich to send mail to.
getDeliveryReceipt()
get delivery receipt
setFrom($_strFrom)
FROM Address from which mail will be sent.
get_RCPT_list()
Returns an array of bare addresses for use with 'RCPT TO:' This is a "build as you go" method.
_getTextTransferEncoding($text)
Content-Transfer-Encoding of a text part: the text is sent as is, so it is '8bit' when it has non ASC...
setID($_strID)
User Name for authentication on Mail Server.
getMoreInHeader()
get moreInHeader
getPW()
Retrieves the User Password for authentication on Mail Server.
getSubject()
Retrieves the Message Subject.
getXheader()
Retrieves the Message X-Header Content.
setErrorsTo($_strErrorsTo)
Set errors to.
setImageInline($strContent, $strImageName='unknown', $strMimeType='unknown', $strImageCid='unknown')
Image attachments are added to the content array as sub-arrays, allowing for multiple images for each...
setMessageID($_msgId='')
Set Message-ID.
setHost($_strHost)
Defines the Host Name or IP of the Mail Server to use.
getFrom($_part=true)
Retrieves the Address from which mail will be sent.
getHost()
Retrieves the Host Name or IP of the Mail Server to use This is used only with 'socket' based mail tr...
setPW($_strPW)
User Password for authentication on Mail Server.
getReplyTo($_part=true)
Retrieves the Address from which mail will be the reply-to.
setPriority($_value=3)
Message Content Priority Message Priority values:
setMoreInHeader($_val='')
Set moreInHeader.
getErrorsTo($_part=true)
Get errors to.
getSensitivity()
Returns Message Content Sensitivity string Message Sensitivity values:
setSMTPTimeout($timeout)
Set socket timeout.
getPort()
Retrieves the Port Number of the Mail Server to use This is used only with 'socket' based mail transm...
getTransportType()
Return the method inwhich the message is to be sent.
setMailPath($_path)
Path to the sendmail executable.
getTransEncode()
Retrieves the Content-Transfer-Encoding.
getReferences()
Retrieves the References from which mail will be the reply-to.
setTransEncode($_strTransEncode)
Content-Transfer-Encoding, Defaulted to '7bit' This can be changed for 2byte characters sets Known En...
_server_authenticate($withauth=true)
Attempt mail server authentication for a secure connection.
setDebug($_vDebug=false)
Set debug.
setDeliveryReceipt($_val=0)
Set delivery receipt.
_setErr($_errNum, $_errMsg)
Defines errors codes and messages for Class.
getHeader()
Constructs and returns message header.
setXheader($strXdata)
Message X-Header Content This is a simple "insert".
is_ip($ip)
This function evaluates a string that should be a valid IPv4 Note: For ip 169.254....
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
getDomainFromURL($url, $mode=0)
Function get second level domain name.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.