Commit 299279cb authored by Sebastian Castro's avatar Sebastian Castro

Use configurable email for automated messages

parent a10f9629
......@@ -30,8 +30,8 @@ fos_user:
service:
mailer: fos_user.mailer.twig_swift
from_email:
address: nepasrepondre@presdecheznous.fr
sender_name: Près de chez nous
address: "%mailer_user%"
sender_name: "%instance_name%"
group:
group_class: Application\Sonata\UserBundle\Document\Group
......
......@@ -17,6 +17,7 @@ parameters:
# CONTACT EMAIL (displayed on error messages)
contact_email: "contact@localhost.fr"
instance_name: "GoGoCarto"
# A secret key that's used to generate certain security-related tokens
secret: ThisTokenIsNotSoSecretChangeIt
......
......@@ -47,12 +47,15 @@ class MailTestController extends Controller
if ($draftResponse['success'])
{
$mailContent = $mailService->sendMail($mail,$draftResponse['subject'], $draftResponse['content']);
$request->getSession()->getFlashBag()->add('success', 'Le mail a bien été envoyé à ' . $mail . '</br>Si vous ne le voyez pas vérifiez dans vos SPAMs');
$result = $mailService->sendMail($mail,$draftResponse['subject'], $draftResponse['content']);
if ($result['success'])
$request->getSession()->getFlashBag()->add('success', 'Le mail a bien été envoyé à ' . $mail . '</br>Si vous ne le voyez pas vérifiez dans vos SPAMs');
else
$request->getSession()->getFlashBag()->add('error', $result['message']);
}
else
{
$request->getSession()->getFlashBag()->add('error', 'Error : ' . $draftResponse['message']);
$request->getSession()->getFlashBag()->add('error', 'Erreur : ' . $draftResponse['message']);
}
return $this->redirectToRoute('biopen_mail_draft_automated', array('mailType' => $mailType));
}
......
......@@ -14,7 +14,7 @@ services:
biopen.mail_service:
class: Biopen\CoreBundle\Services\MailService
arguments: [ "@doctrine.odm.mongoDB.document_manager", "@mailer", "@router", "@twig", "%base_url%", "%base_path%", "%use_as_saas" ]
arguments: [ "@doctrine.odm.mongoDB.document_manager", "@mailer", "@router", "@twig", "%base_url%", "%base_path%", "%use_as_saas%", "%mailer_user%", "%instance_name%" ]
biopen.newsletter_service:
class: Biopen\CoreBundle\Services\NewsletterService
......
......@@ -15,11 +15,13 @@ class MailService
protected $router;
protected $twig;
protected $baseUrl;
protected $email;
protected $instanceName;
/**
* Constructor
*/
public function __construct(DocumentManager $documentManager, $mailer, $router, $twig, $baseUrl, $basePath, $sass)
public function __construct(DocumentManager $documentManager, $mailer, $router, $twig, $baseUrl, $basePath, $sass, $email, $instanceName)
{
$this->em = $documentManager;
$this->config = $this->em->getRepository('BiopenCoreBundle:Configuration')->findConfiguration();
......@@ -30,12 +32,13 @@ class MailService
$this->baseUrl = 'http://';
if ($sass) $this->baseUrl .= $this->config->getDbName() . '.';
$this->baseUrl .= $baseUrl;
$this->email = $email;
$this->instanceName = $instanceName;
}
public function sendMail($to, $subject, $content, $from = null, $toBCC = null)
{
// TODO config an admin email for automated message
if (!$from) $from = array('nepasrepondre@presdecheznous.fr' => 'Près de chez Nous');
if (!$from) $from = array($this->email => $this->instanceName);
try {
$draftedContent = $this->draftTemplate($content);
......@@ -50,7 +53,7 @@ class MailService
if ($to) $message->setTo($to);
if ($toBCC) $message->setBcc($toBCC);
$this->mailer->send($message);
}
catch (\Swift_RfcComplianceException $e) {
......
......@@ -162,10 +162,9 @@ class ElementInteractionController extends Controller
$user = $securityContext->getToken()->getUser();
$senderMail = $request->get('userEmail');
//if ($user && $user->isAdmin()) $senderMail = "contact@presdecheznous.fr"; // TODO replace by gogoconfig contactMail field
// TODO make it configurable
$mailSubject = 'Message reçu depuis la plateforme "Près de Chez Nous"';
$mailSubject = 'Message reçu depuis la plateforme ' . $this->getParameter('instance_name');
$mailContent =
"<p>Bonjour <i>" . $element->getName() . '</i>,</p>
<p>Vous avez reçu un message de la part de <a href="mailto:' . $senderMail . '">' . $senderMail . "</a></br>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment