dev-master
9999999-devSMTP Server based on ReactPHP
MIT
The Requires
server event parse smtp reactphp
v0.1
0.1.0.0SMTP Server based on ReactPHP
MIT
The Requires
server event parse smtp reactphp
SMTP Server based on ReactPHP
SMTP Server based on ReactPHP., (*1)
Widely inspired from SAM-IT/react-smtp., (*2)
Features: * supports many concurrent SMTP connections * supports anonymous connections * supports PLAIN, LOGIN and CRAM-MD5 authentication methods * use Symfony event dispatcher, (*4)
It is advised to install additionnal PHP libraries: * events * mailparse, (*5)
By default, username
and password
are not checked. However, you can override the Server
class to implement your own logic., (*6)
class MyServer extends \Smalot\Smtp\Server\Server { /** * @param Connection $connection * @param MethodInterface $method * @return bool */ public function checkAuth(Connection $connection, MethodInterface $method) { $username = $method->getUsername(); $password = $this->getPasswordForUsername(); return $method->validateIdentity($password); } /** * @param string $username * @return string */ protected function getPasswordForUsername($username) { // @Todo: Load password from Database or somewhere else. $password = ''; return $password; } }
include 'vendor/autoload.php'; try { $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $logger = new \Monolog\Logger('log'); $dispatcher->addSubscriber(new \Smalot\Smtp\Server\Event\LogSubscriber($logger)); $loop = React\EventLoop\Factory::create(); $server = new \Smalot\Smtp\Server\Server($loop, $dispatcher); // Enable 3 authentication methods. $server->authMethods = [ \Smalot\Smtp\Server\Connection::AUTH_METHOD_LOGIN, \Smalot\Smtp\Server\Connection::AUTH_METHOD_PLAIN, \Smalot\Smtp\Server\Connection::AUTH_METHOD_CRAM_MD5, ]; // Listen on port 25. $server->listen(25); $loop->run(); } catch(\Exception $e) { var_dump($e); }
include 'vendor/autoload.php'; try { $mail = new PHPMailer(); $mail->isSMTP(); $mail->Host = 'localhost'; $mail->Port = 25; $mail->SMTPDebug = true; $mail->SMTPAuth = true; $mail->Username = "foo@gmail.com"; $mail->Password = "foo@gmail.com"; $mail->setFrom('from@example.com', 'Mailer'); $mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient $mail->addAddress('ellen@example.com'); // Name is optional $mail->addReplyTo('info@example.com', 'Information'); $mail->addCC('cc@example.com'); $mail->addBCC('bcc@example.com'); $mail->Subject = 'Here is the subject'; $mail->Body = 'This is the HTML message body <b>in bold!</b>'; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent'; } } catch(\Exception $e) { var_dump($e); }
Sample project code for both client
and server
parts., (*7)
{ "require": { "react/event-loop": "^0.4.2", "smalot/smtp-server": "dev-master", "phpmailer/phpmailer": "^5.2" }, "repositories": [ { "type": "vcs", "url": "git@github.com:smalot/react-smtp.git" } ] }
Using the "php-mime-mail-parser/php-mime-mail-parser": "^2.6"
package, you can parse the whole message., (*8)
doc: https://packagist.org/packages/php-mime-mail-parser/php-mime-mail-parser, (*9)
However, need to install the mailparse
PHP Extension.
To do such a thing, you need to install the mbstring
PHP Extension, compile it with PEAR
and enable the mailparse
extension after the mbstring
(using a higher digit)., (*10)
It should be necessary to alter source code to remove the check on mbstring
existence due to an error in this check., (*11)
SMTP Server based on ReactPHP
MIT
server event parse smtp reactphp
SMTP Server based on ReactPHP
MIT
server event parse smtp reactphp