public function __construct($isException = false)
{
// Configuração de remetente
$config = RW_Config::getApplicationIni();
$this->_name = $config->cms->email->name;
$this->_email = $config->cms->email->email;
$this->_returnPath = $config->cms->email->returnPath;
// Verifica se está em ambiente de teste
if (APPLICATION_ENV != 'production') {
$this->_name .= ' (teste local)';
$this->_email = '*****@*****.**';
}
// Configuração de envio de email
$default = Zend_Mail::getDefaultTransport();
// Verifica se há transport a ser usado
if (empty($default)) {
if ($isException instanceof Zend_Mail_Transport_Abstract) {
$transport = $isException;
} else {
$this->_type = $isException ? 'exception' : $config->cms->email->type;
$this->_username = isset($config->cms->email->smtp) ? $config->cms->email->smtp->username : '';
$this->_password = isset($config->cms->email->smtp) ? $config->cms->email->smtp->password : '';
// Configura o método de envio
if ($this->_type == 'exception') {
$transport = new Zend_Mail_Transport_Sendmail('-f' . $this->_returnPath);
// Envio do servidor local. Deve impedir que o cliente receba sem querer
} elseif (APPLICATION_ENV != 'production') {
$transport = new Zend_Mail_Transport_Sendmail("*****@*****.**");
// Configurações da Locaweb
} elseif ($this->_type == 'locaweb') {
/*
* Return-Path padrão da Locaweb
* sendmail_path = /usr/sbin/sendmail -t -i -r'*****@*****.**'
*/
$transport = new Zend_Mail_Transport_Sendmail("-f{$this->_returnPath}");
// Configurações do GMail
} elseif ($this->_type == 'gmail') {
$serverconfig = array('auth' => 'login', 'username' => $this->_username, 'password' => $this->_password, 'ssl' => 'ssl', 'port' => 465);
$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $serverconfig);
// Configuração genérica de SMTP
} elseif ($this->_type == 'smtp') {
$serverconfig = array('auth' => 'login', 'username' => $this->_username, 'password' => $this->_password);
// Verifica se há SSL
if (isset($config->cms->email->smtp->ssl) && $config->cms->email->smtp->ssl != '') {
$serverconfig['ssl'] = $config->cms->email->smtp->ssl;
}
// veriufica se há uma porta definida
if (isset($config->cms->email->smtp->port) && $config->cms->email->smtp->port != '') {
$serverconfig['port'] = $config->cms->email->smtp->port;
}
// Configura o transport
$transport = new Zend_Mail_Transport_Smtp($config->cms->email->smtp->host, $serverconfig);
} else {
throw new Exception('Tipo de envio <b>' . $this->_type . '</b> não definido em RW_Mail');
}
}
// Grava o transport a ser usado para envio de emails
Zend_Mail::setDefaultTransport($transport);
}
}