|
|
|
@ -9,8 +9,10 @@ use App\Entity\Poll;
|
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
|
use Exception;
|
|
|
|
|
use Swift_Mailer;
|
|
|
|
|
use Swift_Message;
|
|
|
|
|
use Symfony\Component\Mailer\Mailer;
|
|
|
|
|
use Symfony\Component\Mailer\MailerInterface;
|
|
|
|
|
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
|
|
|
|
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
|
|
|
|
|
use Symfony\Component\Mime\Address;
|
|
|
|
|
use Symfony\Component\Mime\Email;
|
|
|
|
|
|
|
|
|
@ -21,17 +23,19 @@ class MailService {
|
|
|
|
|
* @var EntityManagerInterface
|
|
|
|
|
*/
|
|
|
|
|
private $em;
|
|
|
|
|
/**
|
|
|
|
|
* @var Swift_Mailer
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
private $mailer;
|
|
|
|
|
|
|
|
|
|
public function __construct( EntityManagerInterface $entityManager, Swift_Mailer $mailer ) {
|
|
|
|
|
public function __construct( EntityManagerInterface $entityManager ) {
|
|
|
|
|
$this->em = $entityManager;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$transport = new EsmtpTransport();
|
|
|
|
|
$mailer = new Mailer($transport);
|
|
|
|
|
$this->mailer = $mailer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function sendCreationMailAction( Owner $foundOwner, Poll $newpoll, Swift_Mailer $mailer ) {
|
|
|
|
|
public function sendCreationMailAction( Owner $foundOwner, Poll $newpoll, MailerInterface $mailer ) {
|
|
|
|
|
$em = $this->em->getRepository( Owner::class );
|
|
|
|
|
$admin_user = $foundOwner;
|
|
|
|
|
$poll = $newpoll;
|
|
|
|
@ -69,9 +73,6 @@ class MailService {
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function sendOwnerPollsAction( Owner $foundOwner ) {
|
|
|
|
|
$em = $this->em->getRepository( Owner::class );
|
|
|
|
|
$admin_user = $foundOwner;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// anti spam , limit to every minute TODO
|
|
|
|
|
// $lastSend = $admin_user->getRequestedPollsDate();
|
|
|
|
@ -87,14 +88,14 @@ class MailService {
|
|
|
|
|
$titleEmail = 'Framadate | Mes sondages';
|
|
|
|
|
|
|
|
|
|
$templateVars = [
|
|
|
|
|
'owner' => $admin_user,
|
|
|
|
|
'owner' => $foundOwner,
|
|
|
|
|
'title' => $titleEmail,
|
|
|
|
|
'email_template' => 'emails/owner-list.html.twig',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$email = ( new TemplatedEmail() )
|
|
|
|
|
->from( 'ne-pas-repondre@framadate-api.cipherbliss.com' )
|
|
|
|
|
->to( new Address( $admin_user->getEmail() ) )
|
|
|
|
|
->to( new Address( $foundOwner->getEmail() ) )
|
|
|
|
|
->subject( $titleEmail )
|
|
|
|
|
->htmlTemplate( $templateVars[ 'email_template' ] )
|
|
|
|
|
->context( $templateVars );
|
|
|
|
|