Skip to content

Commit 09013cf

Browse files
committed
support tlsv1.0 tlsv1.1 tlsv1.2
1 parent cf3af43 commit 09013cf

File tree

6 files changed

+46
-89
lines changed

6 files changed

+46
-89
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
},
2424
"require-dev": {
2525
"phpunit/phpunit": "~4.0",
26-
"erb/testing-tools": "dev-master",
2726
"monolog/monolog": "~1.13"
2827
},
2928
"autoload": {

src/Mailer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function __construct(LoggerInterface $logger=null)
5858
* set server and port
5959
* @param string $host server
6060
* @param int $port port
61-
* @param string $secure ssl tls
61+
* @param string $secure ssl tls tlsv1.0 tlsv1.1 tlsv1.2
6262
* @return $this
6363
*/
6464
public function setServer($host, $port, $secure=null)

src/Mailer/SMTP.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class SMTP
4242
protected $port;
4343

4444
/**
45-
* smtp secure ssl tls
45+
* smtp secure ssl tls tlsv1.0 tlsv1.1 tlsv1.2
4646
*/
4747
protected $secure;
4848

@@ -103,7 +103,7 @@ public function __construct(LoggerInterface $logger=null)
103103
* set server and port
104104
* @param string $host server
105105
* @param int $port port
106-
* @param string $secure ssl tls
106+
* @param string $secure ssl tls tlsv1.0 tlsv1.1 tlsv1.2
107107
* @return $this
108108
*/
109109
public function setServer($host, $port, $secure=null)
@@ -169,7 +169,7 @@ public function send(Message $message)
169169
$this->connect()
170170
->ehlo();
171171

172-
if (substr($this->secure, 0, 3) === 'tls') {
172+
if ($this->secure === 'tls' || $this->secure === 'tlsv1.0' || $this->secure === 'tlsv1.1' | $this->secure === 'tlsv1.2') {
173173
$this->starttls()
174174
->ehlo();
175175
}

tests/MailerTest.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,8 @@
99
class MailerTest extends TestCase
1010
{
1111

12-
/** @var SMTP */
13-
protected $smtp;
14-
/** @var Message */
15-
protected $message;
16-
1712
public function setup()
1813
{
19-
$this->smtp = new SMTP(new Logger('SMTP'));
20-
$this->message = new Message();
21-
}
22-
23-
public function testSMTP()
24-
{
25-
$this->smtp
26-
->setServer(self::SERVER, self::PORT)
27-
->setAuth(self::USER, self::PASS); // email, password
28-
29-
$this->message
30-
->setFrom(self::FROM_NAME, self::FROM_EMAIL) // your name, your email
31-
//->setFakeFrom('Hello', 'bot@fakeemail.com') // a fake name, a fake email
32-
->addTo(self::TO_NAME, self::TO_EMAIL)
33-
->addCc(self::CC_NAME, self::CC_EMAIL)
34-
->addBcc(self::BCC_NAME, self::BCC_EMAIL)
35-
->setSubject('Test SMTP ' . time())
36-
->setBody('<h1>for test</h1>')
37-
->addAttachment('test', __FILE__);
38-
39-
$status = $this->smtp->send($this->message);
40-
$this->assertTrue($status);
41-
usleep(self::DELAY);
4214
}
4315

4416
public function testSend()

tests/SMTPTest.php

Lines changed: 39 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
use Tx\Mailer\SMTP;
1010
use Tx\Mailer\Message;
11-
use ERB\Testing\Tools\TestHelper;
11+
use \Monolog\Logger;
1212

1313
/**
1414
* Class SMTPTest
@@ -26,89 +26,79 @@ class SMTPTest extends TestCase
2626
protected $smtp;
2727

2828
/**
29-
* @var TestHelper
29+
* @var Message
3030
*/
31-
protected $testHelper;
32-
33-
/** @var Message */
3431
protected $message;
3532

36-
3733
public function setup()
3834
{
39-
$this->smtp = new SMTP();
40-
$this->testHelper = new TestHelper();
4135
$this->message = new Message();
42-
$this->message->setFrom('You', 'nobody@nowhere.no')
43-
->addTo('Them', 'them@nowhere.no')
44-
->setSubject('This is a test')
45-
->setBody('This is a test part two');
46-
usleep(self::DELAY);
47-
}
48-
49-
public function testSetServer()
50-
{
51-
$result = $this->smtp->setServer('localhost', '25', null);
52-
$this->assertEquals('localhost', $this->testHelper->getPropertyValue($this->smtp, 'host'));
53-
$this->assertEquals('25', $this->testHelper->getPropertyValue($this->smtp, 'port'));
54-
$this->assertSame($this->smtp, $result);
55-
usleep(self::DELAY);
56-
}
57-
58-
public function testSetAuth()
59-
{
60-
$result = $this->smtp->setAuth('none', 'none');
61-
62-
$this->assertEquals('none', $this->testHelper->getPropertyValue($this->smtp, 'username'));
63-
$this->assertEquals('none', $this->testHelper->getPropertyValue($this->smtp, 'password'));
64-
$this->assertSame($this->smtp, $result);
36+
$this->message
37+
->setFrom(self::FROM_NAME, self::FROM_EMAIL) // your name, your email
38+
//->setFakeFrom('Hello', 'bot@fakeemail.com') // a fake name, a fake email
39+
->addTo(self::TO_NAME, self::TO_EMAIL)
40+
->addCc(self::CC_NAME, self::CC_EMAIL)
41+
->addBcc(self::BCC_NAME, self::BCC_EMAIL)
42+
->setSubject('Test SMTP ' . time())
43+
->setBody('<h1>for test</h1>')
44+
->addAttachment('test', __FILE__);
6545
usleep(self::DELAY);
6646
}
6747

68-
public function testMessage()
48+
public function testSend()
6949
{
70-
$this->smtp->setServer(self::SERVER, self::PORT, null)
50+
$this->smtp = new SMTP(new Logger('SMTP'));
51+
$this->smtp
52+
->setServer(self::SERVER, self::PORT)
7153
->setAuth(self::USER, self::PASS);
7254

7355
$status = $this->smtp->send($this->message);
7456
$this->assertTrue($status);
7557
usleep(self::DELAY);
7658
}
7759

78-
public function testTLSMessage()
60+
public function testTLSSend()
7961
{
80-
$this->smtp->setServer(self::SERVER, self::PORT, 'tls')
81-
->setAuth(self::USER, self::PASS);
62+
$this->smtp = new SMTP(new Logger('SMTP.tls'));
63+
$this->smtp
64+
->setServer(self::SERVER, self::PORT_TLS, 'tls')
65+
->setAuth(self::USER, self::PASS);
8266

8367
$status = $this->smtp->send($this->message);
8468
$this->assertTrue($status);
8569
usleep(self::DELAY);
8670
}
8771

88-
public function testTLSv10Message()
72+
public function testTLSv10Send()
8973
{
90-
$this->smtp->setServer(self::SERVER, self::PORT, 'tlsv1.0')
91-
->setAuth(self::USER, self::PASS);
74+
$this->smtp = new SMTP(new Logger('SMTP.tlsv1.0'));
75+
$this->smtp
76+
->setServer(self::SERVER, self::PORT_TLS, 'tlsv1.0')
77+
->setAuth(self::USER, self::PASS);
9278

9379
$status = $this->smtp->send($this->message);
9480
$this->assertTrue($status);
9581
usleep(self::DELAY);
9682
}
9783

98-
public function testTLSv11Message()
84+
public function testTLSv11Send()
9985
{
100-
$this->smtp->setServer(self::SERVER, self::PORT, 'tlsv1.1')
101-
->setAuth(self::USER, self::PASS);
86+
$this->smtp = new SMTP(new Logger('SMTP.tlsv1.1'));
87+
$this->smtp
88+
->setServer(self::SERVER, self::PORT_TLS, 'tlsv1.1')
89+
->setAuth(self::USER, self::PASS);
10290

10391
$status = $this->smtp->send($this->message);
10492
$this->assertTrue($status);
10593
usleep(self::DELAY);
10694
}
10795

108-
public function testTLSv12Message()
96+
public function testTLSv12Send()
10997
{
110-
$this->smtp->setServer(self::SERVER, self::PORT, 'tlsv1.2')
111-
->setAuth(self::USER, self::PASS);
98+
$this->smtp = new SMTP(new Logger('SMTP.tlsv1.2'));
99+
$this->smtp
100+
->setServer(self::SERVER, self::PORT_TLS, 'tlsv1.2')
101+
->setAuth(self::USER, self::PASS);
112102

113103
$status = $this->smtp->send($this->message);
114104
$this->assertTrue($status);
@@ -120,17 +110,13 @@ public function testTLSv12Message()
120110
*/
121111
public function testConnectSMTPException()
122112
{
123-
$this->smtp->setServer('localhost', "99999", null)
113+
$this->smtp = new SMTP(new Logger('SMTP.FakePort'));
114+
$this->smtp
115+
->setServer('localhost', "99999", null)
124116
->setAuth('none', 'none');
125-
$message = new Message();
126-
$message->setFrom('You', 'nobody@nowhere.no')
127-
->addTo('Them', 'them@nowhere.no')
128-
->setSubject('This is a test')
129-
->setBody('This is a test part two');
130117

131-
$this->smtp->send($message);
118+
$this->smtp->send($this->message);
132119
usleep(self::DELAY);
133120
}
134121

135-
136122
}

tests/TestCase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
class TestCase extends \PHPUnit_Framework_TestCase
77
{
88
/** SMTP server to test against */
9-
const SERVER = 'mailtrap.io';
9+
const SERVER = 'smtp.mailtrap.io';
1010
/** plain text port */
11-
const PORT = 25;
11+
const PORT = 2525;
1212
/** TLS port */
1313
const PORT_TLS = 465;
1414
/** SSL port (not supported by mailtrap currently */
15-
const PORT_SSL = 25;
15+
const PORT_SSL = 0;
1616
/** user for LOGIN auth */
1717
const USER = 'e3f534cfe656f4';
1818
/** password for LOGIN auth */

0 commit comments

Comments
 (0)