forked from clue/reactphp-http-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12-proxy-smtps.php
33 lines (25 loc) · 1.14 KB
/
12-proxy-smtps.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
// A simple example which uses a secure SMTP connection to Googlemail through a HTTP CONNECT proxy.
// Proxy can be given as first argument and defaults to localhost:8080 otherwise.
// This example highlights how changing from plain connections (see previous
// example) to using a secure connection actually adds very little complexity
// and does not mess with your actual network protocol otherwise.
// Please note that MANY public proxies do not allow SMTP connections, YMMV.
use Clue\React\HttpProxy\ProxyConnector;
use React\Stream\Stream;
use React\SocketClient\TcpConnector;
use React\SocketClient\SecureConnector;
require __DIR__ . '/../vendor/autoload.php';
$url = isset($argv[1]) ? $argv[1] : '127.0.0.1:8080';
$loop = React\EventLoop\Factory::create();
$connector = new TcpConnector($loop);
$proxy = new ProxyConnector($url, $connector);
$ssl = new SecureConnector($proxy, $loop);
$ssl->create('smtp.googlemail.com', 465)->then(function (Stream $stream) {
$stream->write("EHLO local\r\n");
$stream->on('data', function ($chunk) use ($stream) {
echo $chunk;
$stream->write("QUIT\r\n");
});
}, 'printf');
$loop->run();