Mise en place des la nouvelle architecture des mails

This commit is contained in:
Michael RICOIS 2015-06-10 14:52:05 +00:00
parent bc6aa8dd56
commit 414aaf0b06
15 changed files with 71 additions and 42 deletions

View File

@ -51,7 +51,7 @@ class ErrorController extends Zend_Controller_Action
$message.= "Referer : ".$_SERVER['HTTP_REFERER']."\n";
$c = Zend_Registry::get('config');
$mail = new Scores_Mail();
$mail = new Scores_Mail_Method();
$mail->setSubject('[ERREUR APPLICATIVE] - '.$c->profil->server->name.' -'.date('Ymd'));
$mail->setBodyTexte($message);
$mail->setFrom('supportdev');

View File

@ -258,7 +258,7 @@ class EvaluationController extends Zend_Controller_Action
$identite = $ws->getIdentite($siren);
$indiscore = $ws->getIndiScore($siren);
$infos = $ws->getRatios($siren, 'indiscore2');
$score = array();
$tabRatio = array(
'r5' => array('total'=>'r5', 'total_info'=>'% ca', 'op' => 1000, 'titre'=>'CHIFFRE D\'AFFAIRES'),
@ -307,7 +307,7 @@ class EvaluationController extends Zend_Controller_Action
$dataTotal[$idRatio] = $ratiosData->dTotal($typeBilan, $annee, $idRatio, $valRatio['total']);
$dInfo[$idRatio] = $valRatio['total_info'];
}
$date = new Zend_Date($annee, 'yyyyMMdd');
$tabResult[] = array(
'dateCloture' => $date->toString('dd/MM/yyyy'),
@ -815,7 +815,7 @@ class EvaluationController extends Zend_Controller_Action
$texte = "<pre>".print_r($InfoUser, 1)."</pre>".
"<pre>".print_r($InfoEnq, 1)."</pre>";
$mail = new Scores_Mail();
$mail = new Scores_Mail_Method();
$mail->setFrom('production');
$mail->addToKey('support');
$mail->setSubject($sujet);
@ -975,7 +975,7 @@ class EvaluationController extends Zend_Controller_Action
if (preg_match('#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,5}$#',$email)) {
$message = 'Entreprise mise sous surveillance scoring partenaire !';
$mail = new Scores_Mail();
$mail = new Scores_Mail_Method();
$mail->setSubject("Demande de surveillance score CreditSafe pour $siren à ".$email);
$user = new Scores_Utilisateur();

View File

@ -179,7 +179,7 @@ class JuridiqueController extends Zend_Controller_Action
}
$this->view->headTitle()->prepend('Annonces Légales - '.$titre);
}
// ---- Calcul pagination
$nbReponses = count($infos->result->item);
$nbReponsesTotal = $infos->nbReponses;

View File

@ -305,7 +305,7 @@ class RechercheController extends Zend_Controller_Action
$message.= "Prénom : ".$user->getPrenom()."<br/>";
$objet = "Demande d'investigation";
$mail = new Scores_Mail();
$mail = new Scores_Mail_Method();
$mail->setFrom('contact');
$mail->addToKey('support');
$mail->setSubject($objet);
@ -560,7 +560,7 @@ class RechercheController extends Zend_Controller_Action
$nbReponses = 0;
$nbReponsesTotal = 0;
if (is_object($reponse) && $reponse !== false)
{
$etabs = $reponse->result->item;

View File

@ -694,7 +694,7 @@ class UserController extends Zend_Controller_Action
$mailbody .= "Aussi nous vous invitons à vous rapprocher de votre interlocuteur commercial habituel ";
$mailbody .= "ou de votre responsable suivi relations Scores & Décisions au sein de votre société.</p>";
$mail = new Scores_Mail();
$mail = new Scores_Mail_Method();
$mail->setSubject("Demande d'envoi des identifiants");
$mail->setBodyHTML($mailbody);
$mail->setFrom('support');

View File

@ -93,7 +93,7 @@ class Scores_Insee_AvisSituation
'http://avis-situation-sirene.insee.fr'.EOL.
'pour login '.$user->getLogin().EOL;
$mail = new Scores_Mail();
$mail = new Scores_Mail_Method();
$mail->setFrom('contact');
$mail->addToKey('support');
$mail->setSubject($objet);

View File

@ -1,34 +1,63 @@
<?php
class Scores_Mail
class Scores_Mail_Method
{
protected $config;
protected $mail;
protected $transport;
/**
* Gestion de l'envoi des mails en fonction de la configuration
* Fournir un élément de configuration ou utiliser la configuration de l'application
*
* method => smtp, sendmail, file
* Si method = smtp
* (host => IP, dns)
*
* Activer l'authentification
* (auth => login, plain, ....)
* (username => )
* (password => )
*/
public function __construct()
public function __construct( $config = null )
{
$c = Zend_Registry::get('config');
$this->config = $c->profil->mail;
$this->mail = new Zend_Mail();
if ($this->config->method == 'smtp') {
$tr = new Zend_Mail_Transport_Smtp($this->config->smtp_host);
$this->mail->setDefaultTransport($tr);
} elseif ($this->config->method == 'smtpauth') {
$cnfg = array(
'auth' => 'login',
'username' => $this->config->username,
'password' => $this->config->password
);
$tr = new Zend_Mail_Transport_Smtp($this->config->smtp_host, $cnfg);
$this->mail->setDefaultTransport($tr);
} else {
$tr = new Zend_Mail_Transport_Sendmail();
$this->mail->setDefaultTransport($tr);
// --- Configuration du transport SMTP
if ( $this->config->method == 'smtp' ) {
$config = array();
if ( isset($this->config->auth) ) {
$config['auth'] = $this->config->auth;
if ( isset($this->config->username) ) {
$config['username'] = $this->config->username;
}
if ( isset($this->config->password) ) {
$config['password'] = $this->config->password;
}
}
if ( isset($this->config->port) ) {
$config['port'] = $this->config->port;
}
$tr = new Zend_Mail_Transport_Smtp($this->config->host, $config);
}
// --- Configuration transport Sendmail
if ( $this->config->method == 'sendmail' ) {
$tr = new Zend_Mail_Transport_Sendmail();
}
// --- Configuration transport File
if ( $this->config->method == 'file' ) {
$tr = new Zend_Mail_Transport_File(array('callback' => 'recipientFilename'));
}
$this->transport = $tr;
}
/**
@ -63,11 +92,11 @@ class Scores_Mail
/**
* Ajout d'un champ To en spécifiant l'email et le nom qui doit apparaitre
* @param string $email
* @param string $nom
* @param string $name
*/
public function addTo($email, $nom = '')
public function addTo($email, $name = '')
{
$this->mail->addTo($email, $this->txtConvert($nom));
$this->mail->addTo($email, $this->txtConvert($name));
}
/**
@ -102,7 +131,7 @@ class Scores_Mail
*/
public function send()
{
return $this->mail->send();
return $this->mail->send($this->transport);
}
//We suppose that character encoding of strings is UTF-8 on PHP script.
@ -110,4 +139,9 @@ class Scores_Mail
return mb_convert_encoding($string, 'ISO-8859-1', 'UTF-8');
}
protected function recipientFilename($transport)
{
return $transport->recipients . '_' . mt_rand() . '.tmp';
}
}

View File

@ -3419,7 +3419,7 @@ class WsScores
if (APPLICATION_ENV == 'production' || APPLICATION_ENV == 'staging') {
$c = Zend_Registry::get('config');
$mail = new Scores_Mail();
$mail = new Scores_Mail_Method();
$mail->setSubject('[ERREUR SOAP] - '.$c->profil->server->name.' -'.date('Ymd'));
$mail->setBodyTexte($message);
$mail->setFrom('supportdev');

View File

@ -21,12 +21,13 @@ return array(
'Scores_Insee_Iris' => dirname(__FILE__) . '//Insee/Iris.php',
'Scores_Locale_String' => dirname(__FILE__) . '//Locale/String.php',
'Logo' => dirname(__FILE__) . '//Logo.php',
'Scores_Mail' => dirname(__FILE__) . '//Mail.php',
'Scores_Mail_Method' => dirname(__FILE__) . '//Mail/Method.php',
'Mappy' => dirname(__FILE__) . '//Mappy.php',
'Scores_Menu' => dirname(__FILE__) . '//Menu.php',
'Scores_Mobile_Detect' => dirname(__FILE__) . '//Mobile/Detect.php',
'Scores_Pdf_Fpdi' => dirname(__FILE__) . '//Pdf/Fpdi.php',
'Scores_Pdf_Page' => dirname(__FILE__) . '//Pdf/Page.php',
'PdfParser' => dirname(__FILE__) . '//Pdf/PdfParser.php',
'Scores_Pdf_Tcpdf' => dirname(__FILE__) . '//Pdf/Tcpdf.php',
'RapportComment' => dirname(__FILE__) . '//RapportComment.php',
'Scores_Serializer_Adapter_Xml' => dirname(__FILE__) . '//Serializer/Adapter/Xml.php',

View File

@ -730,7 +730,6 @@ table.greffe td.saisie { border-top: 1px dashed; }
padding: 2px 10px;
border-radius: 4px;
background-color: #FFF;
border: 1px solid #000;
text-decoration: none;
}
.text-danger {

View File

@ -26,9 +26,7 @@ resources.view.basePath = APPLICATION_PATH "/views/default"
profil.server.name = development
profil.webservice.url = "http://webservice-2.8.sd.dev"
profil.mail.method = smtp
profil.mail.smtp_host = smtp.free.fr
profil.mail.username = yourusername
profil.mail.password = yourpassword
profil.mail.host = smtp.free.fr
profil.mail.email.support = supportdev@scores-decisions.com
profil.mail.email.supportdev = supportdev@scores-decisions.com
profil.mail.email.contact = supportdev@scores-decisions.com

View File

@ -26,9 +26,6 @@ resources.view.basePath = APPLICATION_PATH "/views/default"
profil.server.name = ns359466
profil.webservice.url = "http://wse.scores-decisions.com:8081";
profil.mail.method = sendmail
profil.mail.smtp_host =
profil.mail.username = yourusername
profil.mail.password = yourpassword
profil.mail.email.support = support@scores-decisions.com
profil.mail.email.supportdev = supportdev@scores-decisions.com
profil.mail.email.contact = contact@scores-decisions.com

View File

@ -174,7 +174,7 @@ $emailTxt.= "<br/>";
$emailTxt.= listeCmd(1);
//Envoi mail
$mail = new Scores_Mail();
$mail = new Scores_Mail_Method();
$mail->setFrom('production');
$mail->addTo('support@scores-decisions.com', 'Pieces');
$mail->setSubject("[COMMANDES PIECES COURRIER] - ".date('d')."/".date('m')."/".date('Y'));

View File

@ -147,7 +147,7 @@ if(count($listeCmd)>0){
$emailTxt.= '<br/>';
//Envoi mail
$mail = new Scores_Mail();
$mail = new Scores_Mail_Method();
$mail->setSubject("[Commandes greffe non receptionné] - ".date('d')."/".date('m')."/".date('Y'));
$mail->setFrom('production');
$mail->addTo('support@scores-decisions.com', 'Support');

View File

@ -193,7 +193,7 @@ if ( isset($opts->rapport) || isset($opts->rapportcomplet) )
$emailTxt = utf8_encode($emailTxt);
}
//Envoi mail
$mail = new Scores_Mail();
$mail = new Scores_Mail_Method();
$mail->setFrom('production');
$mail->addTo('support@scores-decisions.com', 'Support');
$mail->addTo('supportdev@scores-decisions.com', 'Support Dev');