Code Monkey home page Code Monkey logo

net_smtp's Introduction

The Net_SMTP Package

User Documentation

Author: Jon Parise Armin Graefe
Contact: [email protected] [email protected]

The Net_SMTP package uses the PEAR_Error class for all of its error handling.

The Net_Socket package is used as the basis for all network communications. Connection options can be specified via the $socket_options construction parameter:

$socket_options = array('ssl' => array('verify_peer_name' => false));
$smtp = new Net_SMTP($host, null, null, false, 0, $socket_options);

Note: PHP 5.6 introduced OpenSSL changes. Peer certificate verification is now enabled by default. Although not recommended, $socket_options can be used to disable peer verification (as shown above).

The Auth_SASL package is an optional dependency. If it is available, the Net_SMTP package will be able to support the DIGEST-MD5_, CRAM-MD5_ and SCRAM-SHA_ SMTP authentication methods. Otherwise, only the LOGIN_ and PLAIN methods will be available.

All of the Net_SMTP class's public methods return a PEAR_Error object if an error occurs. The standard way to check for a PEAR_Error object is by using PEAR::isError():

if (PEAR::isError($error = $smtp->connect())) {
    die($error->getMessage());
}

The Net_SMTP package supports the SMTP authentication standard (as defined by RFC-2554). The Net_SMTP package supports the following authentication methods, in order of preference:

DEPRECATED This authentication method is no longer secure and should be avoided.

The CRAM-MD5 authentication method has been superseded by the DIGEST-MD5_ method in terms of security. It is provided here for compatibility with older SMTP servers that may not support the newer DIGEST-MD5 algorithm.

Note: The CRAM-MD5 authentication method is only supported if the AUTH_SASL package is available.

DEPRECATED This authentication method is no longer secure and should be avoided.

The DIGEST-MD5 authentication method uses RSA Data Security Inc.'s MD5 Message Digest algorithm. It is considered a more secure method of SMTP authentication than PLAIN or LOGIN, while still vulnerable to MitM attacks without TLS/SSL.

Note: The DIGEST-MD5 authentication method is only supported if the AUTH_SASL package is available.

The GSSAPI authentication method uses Kerberos 5 protocol (RFC-4120). Does not use user/password. Requires Service Principal gssapi_principal parameter and has an optional Credentials Cache gssapi_cname parameter. Requires DNS and Key Distribution Center (KDC) setup. It is considered the most secure method of SMTP authentication.

Note: The GSSAPI authentication method is only supported if the krb5 php extension is available.

DEPRECATED This authentication method is no longer secure and should be avoided.

The LOGIN authentication method encrypts the user's password using the Base64 encoding scheme. Because decrypting a Base64-encoded string is trivial.

This authentication method is no longer secure and should only be used local or via an TLS encrypted connection.

The PLAIN authentication method sends the user's password in plain text.

In cryptography, the Salted Challenge Response Authentication Mechanism (SCRAM) is a family of modern, password-based challenge–response authentication mechanisms providing authentication to a server.

Available mechanisms are SCRAM-SHA-1, SCRAM-SHA-224, SCRAM-SHA-256, SCRAM-SHA-384 and SCRAM-SHA-512.

Note: The SCRAM-SHA authentication method is only supported if the AUTH_SASL package is available.

The XOAUTH2 authentication method sends a username and an OAuth2 access token as per Gmail's SASL XOAUTH2 documentation.

If secure socket transports have been enabled in PHP, it is possible to establish a secure connection to the remote SMTP server:

$smtp = new Net_SMTP('ssl://mail.example.com', 465);

This example connects to mail.example.com on port 465 (a common SMTPS port) using the ssl:// transport.

TLS/SSL is enabled for authenticated connections by default (via the auth() method's $tls parameter), but the STARTTLS command can also be sent manually using the starttls() method.

Message data is sent using the data() method. The data can be supplied as a single string or as an open file resource.

If a string is provided, it is passed through the data quoting system and sent to the socket connection as a single block. These operations are all memory-based, so sending large messages may result in high memory usage.

If an open file resource is provided, the data() method will read the message data from the file line-by-line. Each chunk will be quoted and sent to the socket connection individually, reducing the overall memory overhead of this data sending operation.

Header data can be specified separately from message body data by passing it as the optional second parameter to data(). This is especially useful when an open file resource is being used to supply message data because it allows header fields (like Subject:) to be built dynamically at runtime.

$smtp->data($fp, "Subject: My Subject");

By default, all outbound string data is quoted in accordance with SMTP standards. This means that all native Unix (\n) and Mac (\r) line endings are converted to Internet-standard CRLF (\r\n) line endings. Also, because the SMTP protocol uses a single leading period (.) to signal an end to the message data, single leading periods in the original data string are "doubled" (e.g. "..").

These string transformation can be expensive when large blocks of data are involved. For example, the Net_SMTP package is not aware of MIME parts (it just sees the MIME message as one big string of characters), so it is not able to skip non-text attachments when searching for characters that may need to be quoted.

Because of this, it is possible to extend the Net_SMTP class in order to implement your own custom quoting routine. Just create a new class based on the Net_SMTP class and reimplement the quotedata() method:

require 'Net_SMTP.php';

class Net_SMTP_custom extends Net_SMTP
{
    function quotedata($data)
    {
        /* Perform custom data quoting */
    }
}

Note that the $data parameter will be passed to the quotedata() function by reference. This means that you can operate directly on $data. It also the overhead of copying a large $data string to and from the quotedata() method.

The Net_SMTP package retains the server's last response for further inspection. The getResponse() method returns a 2-tuple (two element array) containing the server's response code as an integer and the response's arguments as a string.

Upon a successful connection, the server's greeting string is available via the getGreeting() method.

The Net_SMTP package contains built-in debugging output routines (disabled by default). Debugging output must be explicitly enabled via the setDebug() method:

$smtp->setDebug(true);

The debugging messages will be sent to the standard output stream by default. If you need more control over the output, you can optionally install your own debug handler.

function debugHandler($smtp, $message)
{
    echo "[$smtp->host] $message\n";
}

$smtp->setDebug(true, "debugHandler");

The following script demonstrates how a simple email message can be sent using the Net_SMTP package:

require 'Net/SMTP.php';

$host = 'mail.example.com';
$from = '[email protected]';
$rcpt = array('[email protected]', '[email protected]');
$subj = "Subject: Test Message\n";
$body = "Body Line 1\nBody Line 2";

/* Create a new Net_SMTP object. */
if (! ($smtp = new Net_SMTP($host))) {
    die("Unable to instantiate Net_SMTP object\n");
}

/* Connect to the SMTP server. */
if (PEAR::isError($e = $smtp->connect())) {
    die($e->getMessage() . "\n");
}

/* Send the 'MAIL FROM:' SMTP command. */
if (PEAR::isError($smtp->mailFrom($from))) {
    die("Unable to set sender to <$from>\n");
}

/* Address the message to each of the recipients. */
foreach ($rcpt as $to) {
    if (PEAR::isError($res = $smtp->rcptTo($to))) {
        die("Unable to add recipient <$to>: " . $res->getMessage() . "\n");
    }
}

/* Set the body of the message. */
if (PEAR::isError($smtp->data($subj . "\r\n" . $body))) {
    die("Unable to send data\n");
}

/* Disconnect from the SMTP server. */
$smtp->disconnect();

net_smtp's People

Contributors

alecpl avatar aleskrajnik avatar ashnazg avatar clockwerx avatar convissor avatar dsoares avatar edouardvanbelle avatar eehakkin avatar haoqis avatar jparise avatar legoktm avatar mj avatar reedy avatar roelvanmeer avatar schengawegga avatar stigsb avatar thomascube avatar till avatar urusha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

net_smtp's Issues

Please update the license on Mail/sendmail.php

The file Mail/sendmail.php is the only file in this module that still uses version 2.02 of the PHP license. Because it has this license, it cannot be packaged on Debian, due to Debian's strict copyright guidelines.

Is it perhaps possible to update the license of this file to the New BSD License, the same license that is used in all the other files in this module?

Composer installation fails

When I require the pear/net_smtppackage like this:

    "require": {
        "pear/Net_SMTP": "*",

I get the following output:

Your requirements could not be resolved to an installable set of packages.

Prblem 1
    - pear/net_smtp dev-topics/composer-for-pear requires pear/net_socket * -> no matching package found.
    - pear/net_smtp dev-master requires pear/net_socket * -> no matching package found.
    - Installation request for pear/net_smtp * -> satisfiable by pear/net_smtp[dev-master, dev-topics/composer-for-pear].

Incorrect behaviour with XOAuth2 and long OAuth2 tokens

The implementation for XOAuth2 does not seem to respect the following part of the RFC 4954:

Note that the AUTH command is still subject to the line length limitations defined in [SMTP]. If use of the initial response argument would cause the AUTH command to exceed this length, the client MUST NOT use the initial response parameter (and instead proceed as defined in Section 5.1 of [SASL]).

If I understand it correctly, the maximum length of the token that can be sent the way it is now (with AUTH XOAUTH2 <token> command) is 512 bytes (SMTP line length limit) - 2 bytes (CRLF) - 13 bytes (length of the literal AUTH XOAUTH2 ) = 497. That applies to the base64-encoded version of the token.

For longer tokens, the multiline variant should be used instead, sending AUTH XOAUTH2, waiting for 334 response from the server and then submitting the whole OAuth2 (JWT) token on the next line.

The problematic code is here:

if (PEAR::isError($error = $this->put('AUTH', 'XOAUTH2 ' . $auth))) {

I also created issue in the Roundcube project (roundcube/roundcubemail#8623) to bring more awareness to the issue, as the implementation here was done by a Roundcube team member.

Also, if I did not understand the issue or the RFC right, I'll be happy for a correction. Otherwise I will start working on a PR.

Thank you!

background process and problems with persistent connection

hi guys, i'm with some problems, runnning a background process forever (execute at server startup and continue live forever) with persistent connection, sometimes it don't work and no exception is displayed, i'm running debug parameter set to true, i will try to develop a test case, but i don't know what could i do to solve this problem

thanks guys

PHP7 support

We need to provide class constructor via __construct().

I think we could also drop PHP4 support.

Server response for get queued as

Hello,

I would like to know if we can configure the response of the server to recover the value of queued as who is get $this->_smpt->getResponse(), because on my server I get this string: "Message queued as .." while in the file smtp.php the chain of Expected character is: "Ok: queued as", I submitted a Pull requests in pear/Mail project to the case where.

Thank you.

SCRAM-SHA-1(-PLUS) + SCRAM-SHA-256(-PLUS) + SCRAM-SHA-512(-PLUS) supports

Can you add the SCRAM supports?

For example Rouncube has needed: roundcube/roundcubemail#6917


Cyrus SASL supports:

  • SCRAM-SHA-1
  • SCRAM-SHA-1-PLUS
  • SCRAM-SHA-224
  • SCRAM-SHA-224-PLUS
  • SCRAM-SHA-256
  • SCRAM-SHA-256-PLUS
  • SCRAM-SHA-384
  • SCRAM-SHA-384-PLUS
  • SCRAM-SHA-512
  • SCRAM-SHA-512-PLUS

-> https://cyrusimap.org/sasl/sasl/authentication_mechanisms.html
-> https://github.com/cyrusimap/cyrus-sasl/commits/master

Dovecot SASL supports:

  • SCRAM-SHA-1
  • SCRAM-SHA-256

-> https://doc.dovecot.org/configuration_manual/authentication/password_schemes/

GNU SASL supports:

  • SCRAM-SHA-1
  • SCRAM-SHA-1-PLUS
  • SCRAM-SHA-256
  • SCRAM-SHA-256-PLUS

-> http://www.gnu.org/software/gsasl/


"When using the SASL SCRAM mechanism, the SCRAM-SHA-256-PLUS variant SHOULD be preferred over the SCRAM-SHA-256 variant, and SHA-256 variants [RFC7677] SHOULD be preferred over SHA-1 variants [RFC5802]".

https://xmpp.org/extensions/inbox/hash-recommendations.html

-PLUS variants:

IMAP:

LDAP:

  • RFC5803: Lightweight Directory Access Protocol (LDAP) Schema for Storing Salted: Challenge Response Authentication Mechanism (SCRAM) Secrets: https://tools.ietf.org/html/rfc5803

HTTP:

2FA:

IANA:

Linked to:

Deprecated new by reference

[Mon Aug 11 17:40:42 2014] [error] [client X.X.X.X] Deprecated: Assigning the return value of new by reference is deprecated\nBacktrace:#0: in "/usr/share/php/Mail/smtp.php" at line 349\n#1
[Mon Aug 11 17:40:43 2014] [error] [client X.X.X.X] Deprecated: Assigning the return value of new by reference is deprecated\nBacktrace:#0: in "/usr/share/php/Mail/smtp.php" at line 349\n#1:

Server version: Apache/2.2.22 (Ubuntu)
Server built: Jul 22 2014 14:37:02
Server's Module Magic Number: 20051115:30
Server loaded: APR 1.4.6, APR-Util 1.3.12
Compiled using: APR 1.4.6, APR-Util 1.3.12
Architecture: 32-bit
Server MPM: Prefork
threaded: no
forked: yes (variable process count)
Server compiled with....
-D APACHE_MPM_DIR="server/mpm/prefork"
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=128
-D HTTPD_ROOT="/etc/apache2"
-D SUEXEC_BIN="/usr/lib/apache2/suexec"
-D DEFAULT_PIDLOG="/var/run/apache2.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_LOCKFILE="/var/run/apache2/accept.lock"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="mime.types"
-D SERVER_CONFIG_FILE="apache2.conf"

php -v
PHP 5.3.10-1ubuntu3.13 with Suhosin-Patch (cli) (built: Jul 7 2014 18:52:09)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

php -m
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
ereg
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
imap
json
libxml
mbstring
memcache
mhash
ming
mssql
mysql
mysqli
openssl
pcntl
pcre
PDO
pdo_dblib
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]

Don't enable GSSAPI method if principal is not set

Ref: roundcube/roundcubemail#9381

When $gssapi_principal is not set the method should become unavailable.

--- SMTP.old    2024-04-13 08:14:00.369484126 +0200
+++ SMTP.php    2024-04-13 08:13:19.873746919 +0200
@@ -206,7 +206,7 @@
         $this->gssapi_cname     = $gssapi_cname;
 
         /* If PHP krb5 extension is loaded, we enable GSSAPI method. */
-        if (extension_loaded('krb5')) {
+        if ($gssapi_principal && extension_loaded('krb5')) {
             $this->setAuthMethod('GSSAPI', array($this, 'authGSSAPI'));
         }
 

Pointer of resource $data is not rewinded after using fstat (SMTP.php line 1034-1075)

Hello Net_SMTP developer!

Please find the following bugfix for a problem, where the email message is empty using resource mail body (used by horde webmailer):

--- SMTP.orig.php       2013-08-26 21:14:43.602400474 +0200
+++ SMTP.php    2013-08-26 21:14:55.801607272 +0200
@@ -1036,6 +1036,7 @@
                 return PEAR::raiseError('Failed to get file size');
             }
             $size += $stat['size'];
+            rewind($data);
         } else {
             $size += strlen($data);
         }

Reason: the pointer is not getting resetted after using fstat($data).
Without rewind($data) theres no data on line 1075 to read...

I am not sure if this is caused by a change in PHP (5.3.17).

Best regards,
Juergen

Edit: not sure on how to post code to that issue tracker... Hopefully the bugfix is clear, otherwise please tell me how to post code like [code] ... [/code]

Edit2: Thank you jparise ;)

A broken symlink in the package makes it impossible to deploy it as part of a CI/CD pipeline

(edit: Typos)

Problem

The /docs directory is not part of the installed files after running composer. That makes the /README.rst link invalid.

Consequence

During a deployment, we have chosen to run composer in a pipeline. During that process, when the broken symlink is encountered by the aws cli (for example), we get No such file or directory and the deployment fails.

Mitigation / Workaround

Delete /README.rst right after running composer install

Proposed solution

  • Do no include any symlink in a library, a repo, etc.
  • In this case, replace README.rst with the actual file from the /docs directory.

STARTTLS issues with certain mail servers

in NET/SMTP.php

this if statement would always error with STARTTLS failed for many email servers.

        if (PEAR::isError($result = $this->socket->enableCrypto(true, $crypto_method))) {
            return $result;
        } elseif ($result !== true) {
            return PEAR::raiseError('STARTTLS failed');
        }

I noticed email servers like office365 and yahoo behaved differently than secureserver.net for example

I commented out the raiseError and it worked in all my situations.

TLS v1.2 connection problem

Hello,

I'm trying to find out why roundcube won't connect to an SMTP server that uses TLS v1.2 as the only available protocol.

I traced the problem down to TLS v1.2 because when the server enables TLS v1.0, then roundcube is able to connect without problems.

What is also interesting, is that roundcube connects fine to the IMAP server with TLS v1.2, only the SMTP protocol seems to have this problem. Apparently this is because it uses a different library for IMAP.

Upon further investigation, I found that roundcube uses Net_SMTP, which in turn uses PHP contexts. Since I'm using CentOS 7 with PHP 5.4.16 and openssl 1.0.1e, everything supports TLS v1.2 without a problem.

In opening this issue, in hope that you will have more information about TLS v1.2 with Net_SMTP.

Thank you.

SMTP: STARTTLS failed (code: 220, response: 2.0.0 Ready to start TLS)

Suddenly my web start to give this error when trying to send an email:

[SMTP: STARTTLS failed (code: 220, response: 2.0.0 Ready to start TLS)]

If enabling debug mode I'm getting this info:

DEBUG: Recv: 220 mail-node-smtp-02.dondominio.com ESMTP DD Mail System
DEBUG: Send: EHLO localhost
DEBUG: Recv: 250-mail-node.dondominio.com
DEBUG: Recv: 250-PIPELINING
DEBUG: Recv: 250-SIZE 51200000
DEBUG: Recv: 250-ETRN
DEBUG: Recv: 250-STARTTLS
DEBUG: Recv: 250-AUTH PLAIN LOGIN
DEBUG: Recv: 250-AUTH=PLAIN LOGIN
DEBUG: Recv: 250-ENHANCEDSTATUSCODES
DEBUG: Recv: 250-8BITMIME
DEBUG: Recv: 250-DSN
DEBUG: Recv: 250 CHUNKING
DEBUG: Send: STARTTLS
DEBUG: Recv: 220 2.0.0 Ready to start TLS
DEBUG: Send: RSET
DEBUG: Recv: \qz0x9|PT&2VVSl1Nu(XaQ4 FUȩKXHiJcRJ~aj_/$-S셀䰖C
DEBUG: Send: QUIT
DEBUG: Recv: r^O_QW]H"F+zt3^E0Fԋת@

After take a look on some forums, I found it can be fixed changing the line 588 of "Net\SMTP.php" from:

&& extension_loaded('openssl') && isset($this->esmtp['STARTTLS'])

to:

&& extension_loaded('openssl') && $this->esmtp['STARTTLS']

After the change everything start to work fine like before.

My setup is WS 2012 R2 with IIS8, PHP8.0 and pear up to date at January date.

Thanks and best regards!

Please clarify LICENSE

See pr #17 for missing file

File headers states version 2.02 of PHP License, when LICENSE file in git states 3.01

Undefined variable: last

I get the following error after upgrading to version 1.7.0:
PHP Notice: Undefined variable: last in /usr/share/php/Net/SMTP.php on line 1087
It seems to me that the two lines
$last = $line;
and
$last = $chunk;
in the function Net_SMTP::data() got lost somehow during the update from version 1.6.3 to 1.7.0.

background process and problems with connection

guys when running as a background process, forever
while(1){ read emails from database; send email; disconnect; }

i get a lot of close_wait at netstat, i think it's a netsocket problem, but i changed net socket to shutdown() and fclose() the socket before close, and it persist, any idea what could we do?

check netstat running 1hour (near to 100emails), i'm using non persistent connections

[beto@xyz ~]# netstat -an | grep CLOSE_WAIT
tcp 54 0 192.168.0.5:34375 208.84.244.140:587 CLOSE_WAIT
tcp 54 0 192.168.0.5:34365 208.84.244.140:587 CLOSE_WAIT
tcp 54 0 192.168.0.5:34390 208.84.244.140:587 CLOSE_WAIT
tcp 54 0 192.168.0.5:34385 208.84.244.140:587 CLOSE_WAIT
tcp 54 0 192.168.0.5:34379 208.84.244.140:587 CLOSE_WAIT
tcp 54 0 192.168.0.5:34369 208.84.244.140:587 CLOSE_WAIT
tcp 54 0 192.168.0.5:34362 208.84.244.140:587 CLOSE_WAIT
tcp 54 0 192.168.0.5:34366 208.84.244.140:587 CLOSE_WAIT
tcp 54 0 192.168.0.5:34360 208.84.244.140:587 CLOSE_WAIT
tcp 54 0 192.168.0.5:34383 208.84.244.140:587 CLOSE_WAIT
tcp 54 0 192.168.0.5:34368 208.84.244.140:587 CLOSE_WAIT
tcp 54 0 192.168.0.5:34364 208.84.244.140:587 CLOSE_WAIT
tcp 54 0 192.168.0.5:34372 208.84.244.140:587 CLOSE_WAIT
tcp 54 0 192.168.0.5:34357 208.84.244.140:587 CLOSE_WAIT

RFC6331: Moving CRAM-MD5, DIGEST-MD5 and LOGIN to Historic

20 November 2008: CRAM-MD5 to Historic:

29 June 2017: CRAM-MD5 to Historic:

July 2011: RFC6331: Moving DIGEST-MD5 to Historic:

I add same about SCRAM-MD5.

There are now:

  • July 2010: RFC5802: Salted Challenge Response Authentication Mechanism (SCRAM): SASL and GSS-API Mechanisms: https://tools.ietf.org/html/rfc5802 (SCRAM-SHA-1 and SCRAM-SHA-1-PLUS)
  • July 2010: RFC5803: Lightweight Directory Access Protocol (LDAP) Schema for Storing Salted: Challenge Response Authentication Mechanism (SCRAM) Secrets: https://tools.ietf.org/html/rfc5803
  • November 2015: RFC7677: SCRAM-SHA-256 and SCRAM-SHA-256-PLUS: Simple Authentication and Security Layer (SASL) Mechanisms: https://tools.ietf.org/html/rfc7677

Soon:

Final MIME boundary gets truncated

Hello, I'm not sure if this is a bug in Net_SMTP. We noticed that the final MIME boundary was always being truncated when communicating with an SMTP server in Net_SMTP 1.7.2 and we confirmed that the behavior is not present in 1.7.1.

In our packet capture, we observed that the final boundary is --=_9ac6a00cd3d2ece6e38e5a24cbee6ea1- instead of --=_9ac6a00cd3d2ece6e38e5a24cbee6ea1--. The second - is missing at the end for some reason. Downgrading to Net_SMTP 1.7.1 solved the problem and emails were being displayed correctly to the recipient.

Below you'll find a copy of the packet trace. I edited the domain names, the subject, and the text/html content to remove some sensitive information. There is no text/plain content so that section is empty.

I hope this helps reproduce the issue, and if it's not a bug in Net_SMTP then I would appreciate being pointed in the right direction.

220 our.domain.example.com
EHLO localhost
250-our.domain.example.com
250-PIPELINING
250-SIZE 10240000
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
MAIL FROM:<[email protected]>
250 2.1.0 Ok
RCPT TO:<[email protected]>
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
MIME-Version: 1.0
Content-Type: multipart/alternative;
 boundary="=_9ac6a00cd3d2ece6e38e5a24cbee6ea1"
Content-Transfer-Encoding: 8bit
From: [email protected]
To: [email protected]
Subject: vos identifiants

--=_9ac6a00cd3d2ece6e38e5a24cbee6ea1
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=UTF-8


--=_9ac6a00cd3d2ece6e38e5a24cbee6ea1
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns=3D"http://www.w3.org/1999/xhtml" xml:lang=3D"en">
<head>
    <meta http-equiv=3D"Content-Type" content=3D"text/html;charset=3DUTF-8"=
 />
</head>
<body style=3D"font-family: 'Arial', 'sans-serif';font-size: 10pt;">
    <p>Bonjour,</p>
</body>
</html>

--=_9ac6a00cd3d2ece6e38e5a24cbee6ea1-
.
250 2.0.0 Ok: queued as A28A244B0D
QUIT
221 2.0.0 Bye

When SMTP server return an erreneous response upon QUIT message, socket is not closed and leaks

Leaking opened TCP socket which remain open as long as the PHP process lives. This especially cause problems when running applications such as long running message bus consumers that sporadically send mails: if you open a new socket per mail, eventually you'll reach a point where you deplete allowed OS open file limit (ulimit).

I'll debug on my side, we reproduced a specific scenario where the server doesn't answer correctly on QUIT command, and I'll open a PR.

Release 1.7.0

Please, release the new version. From my tests on git-master it looks working on PHP7 and PHP5.

When called using PHP 5.5 with error reporting on, get warnings about PEAR isError being called statically

When calling Net_SMTP methods using PHP 5.5 with error reporting on, get a lot of warnings about PEAR isError being called statically. Changing PEAR::isError() to $this->isError() gets rid of warnings.

  ini_set('display_errors', 1); 
  error_reporting(E_ALL|E_STRICT);
  PHP Strict standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /usr/lib64/php/Mail/smtp.php on line 365

  PHP Strict standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /usr/lib64/php/Net/SMTP.php on line 424

  ...

Bug in SMTP.php, fix included

There is a bug in Net/SMTP.php.

1 - Line 1001 of "public function data" you are setting $size to the length of the $headers, if provided separately from the $data.

2 - Line 1010 if $data is a string, you add strlen($data) to the size. $size now equals strlen($headers)+strlen($data).

3 - Line 1033 if the $headers exist you add them to the quotedata

4 - Line 1066 - Line 1095 you loop over $data, breaking it into chunks, but because the headers were sent separately and output separately on line 1033, but you forgot to remove their length from $size, this loop will attempt to read chars from $data at non-existing indexes.

QUICK FIX: Insert after line 1033
$size = strlen($data);

problem with TLS

hi guys i couldn't send email with gmail, i changed the net/socket php file to avoid tls, but the problem is reported here:
http://osticket.com/forum/discussion/3422/failed-to-configure-email-smtp-settings
im using php 5.6, maybe we should change something at socket creation or use a parameter to change socket options

check this comment:


I was getting this error, but even disabling STARTTLS (as several of the above comments suggest) didn't help, as it then reported an authentication error. I found the proper fix for at least my situation.

If you're using PHP 5.6, there are changes to SSL:
http://php.net/manual/en/migration56.openssl.php

Mainly, there is extra verification done on the connection. This verification wasn't done on 5.5 so these issues were ignored. But in my situation, the server was sending the SMTP EHLO command with "localhost" and apparently that causes PHP's new verification to fail.

The solution is to patch osTicket's mail class at /include/pear/Net/SMTP.php - change this line:

$this->_socket_options =$socket_options;

to

$this->_socket_options = array('ssl' => array('verify_peer_name' => false));

This turns the verification off. For my setup, the mail server is on the same local network as the osTicket server, so I'm not overly concerned about the security.

The other solution is to downgrade to PHP 5.5 which doesn't have this extra verification.

It'd be nice if osTicket somehow offered a setting for this so patching the code isn't necessary every time.

PHP Strict Standards

PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 448
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 465
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 472
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 515
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 263
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 519
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 597
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 263
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 600
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 603
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 515
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 263
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 519
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 621
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 802
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 263
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 806
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 814
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 263
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 818
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 822
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 263
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 827
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 649
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 945
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 263
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 948
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 975
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 263
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 978
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 1054
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 263
PHP Strict Standards:  Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /.../Net/SMTP.php on line 1057

Installing pear/net_smtp with composer & --prefer-stable fails

Due to a lack of stable releases for pear/net_socket.

  Problem 2
    - Installation request for pear/net_smtp 1.7.1 -> satisfiable by pear/net_smtp[1.7.1].
    - pear/net_smtp 1.7.1 requires pear/net_socket * -> no matching package found.

I know this is technically an issue against pear/net_socket, but issues are disabled there and the project seems mostly unmaintained.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.