I wrote this a few weeks back and it seems to be working alright. It only
supports AUTH LOGIN and AUTH PLAIN though.
<?php
require_once 'Zend/Mail/Transport/Smtp.php';
class My_Zend_Mail_Transport_Smtp_Auth extends Zend_Mail_Transport_Smtp {
/[EMAIL PROTECTED]
* Authentication types
* @var string
*/
const LOGIN = 'LOGIN';
const PLAIN = 'PLAIN';
/[EMAIL PROTECTED]/
/**
* @param string $username
* @param string $password
* @param string $method
*/
protected function authenticate($username, $password, $method =
self::PLAIN) {
switch($method) {
case self::LOGIN:
$this->authenticateLogin($username, $password);
break;
case self::PLAIN:
$this->authenticatePlain($username, $password);
break;
}
}
/**
* @param string $username
* @param string $password
* @throws Zend_Mail_Transport_Exception
*/
protected function authenticateLogin($username, $password) {
$this->_send('AUTH LOGIN');
try {
$this->_expect(334);
} catch(Zend_Mail_Transport_Exception $e) {
if(substr($e->getMessage(), 0, 3) == 503) {
return;
}
throw $e;
}
$this->_send(base64_encode($username));
$this->_expect(334);
$this->_send(base64_encode($password));
$this->_expect(235);
}
/**
* @param string $username
* @param string $password
* @throws Zend_Mail_Transport_Exception
*/
protected function authenticatePlain($username, $password) {
$this->_send('AUTH PLAIN');
try {
$this->_expect(334);
} catch(Zend_Mail_Transport_Exception $e) {
if(substr($e->getMessage(), 0, 3) == 503) {
return;
}
throw $e;
}
$this->_send(base64_encode(chr(0) . $username . chr(0) .
$password));
$this->_expect(235);
}
}
On 1/31/07, Sanjay Aggarwal <[EMAIL PROTECTED]> wrote:
Right Now SMTP authentication is not there in the mail class. Is there
anyone who has implemented SMTP authentication with Zend Framework any how?
If so - do let me know asap. That will be a great help for us.
Regards,
Sanjay Aggarwal