1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: namespace Jyxo\Beholder\TestCase;
15:
16: 17: 18: 19: 20: 21: 22: 23: 24:
25: class Smtp extends \Jyxo\Beholder\TestCase
26: {
27: 28: 29: 30: 31:
32: private $host;
33:
34: 35: 36: 37: 38:
39: private $to;
40:
41: 42: 43: 44: 45:
46: private $from;
47:
48: 49: 50: 51: 52:
53: private $timeout;
54:
55: 56: 57: 58: 59: 60: 61: 62: 63:
64: public function __construct($description, $host, $to, $from = '', $timeout = 2)
65: {
66: parent::__construct($description);
67:
68: $this->host = (string) $host;
69: $this->to = (string) $to;
70: $this->from = (string) $from;
71: $this->timeout = (int) $timeout;
72:
73:
74: if (empty($this->from)) {
75: $this->from = 'beholder@jyxo.com';
76: }
77: }
78:
79: 80: 81: 82: 83:
84: public function run()
85: {
86:
87: if (!class_exists('\Jyxo\Mail\Sender\Smtp')) {
88: return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::NOT_APPLICABLE, 'Class \Jyxo\Mail\Sender\Smtp missing');
89: }
90:
91: try {
92: $header = 'From: ' . $this->from . "\n";
93: $header .= 'To: ' . $this->to . "\n";
94: $header .= 'Subject: Beholder' . "\n";
95: $header .= 'Date: ' . date(DATE_RFC822) . "\n";
96:
97: $smtp = new \Jyxo\Mail\Sender\Smtp($this->host, 25, $this->host, $this->timeout);
98: $smtp->connect()
99: ->from($this->from)
100: ->recipient($this->to)
101: ->data($header, 'Beholder SMTP Test')
102: ->disconnect();
103: } catch (\Exception $e) {
104: $smtp->disconnect();
105: return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Send error %s', $this->host));
106: }
107:
108:
109: return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::SUCCESS, $this->host);
110: }
111: }
112: