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