mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
testing stuff
This commit is contained in:
parent
e235986483
commit
79c4bd2519
@ -9,10 +9,9 @@ use App\Entity\Owner;
|
|||||||
use App\Entity\Poll;
|
use App\Entity\Poll;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
use Swift_Mailer;
|
||||||
use Symfony\Component\Mailer\Mailer;
|
use Swift_Message;
|
||||||
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
|
use Swift_SmtpTransport;
|
||||||
use Symfony\Component\Mime\Address;
|
|
||||||
|
|
||||||
class MailService {
|
class MailService {
|
||||||
|
|
||||||
@ -27,9 +26,14 @@ class MailService {
|
|||||||
// public function __construct( EntityManagerInterface $entityManager , Mailer $mailer) {
|
// public function __construct( EntityManagerInterface $entityManager , Mailer $mailer) {
|
||||||
public function __construct( EntityManagerInterface $entityManager ) {
|
public function __construct( EntityManagerInterface $entityManager ) {
|
||||||
$this->em = $entityManager;
|
$this->em = $entityManager;
|
||||||
$transport = new EsmtpTransport();
|
|
||||||
$this->mailer = new Mailer( $transport );
|
// Create the Transport
|
||||||
// $this->mailer = $mailer;
|
$transport = new Swift_SmtpTransport( 'localhost', 25 );
|
||||||
|
|
||||||
|
// Create the Mailer using your created Transport
|
||||||
|
$mailer = new Swift_Mailer( $transport );
|
||||||
|
|
||||||
|
$this->mailer = $mailer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -83,6 +87,7 @@ class MailService {
|
|||||||
*
|
*
|
||||||
* @return int|void
|
* @return int|void
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
* @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface
|
||||||
*/
|
*/
|
||||||
public function sendOwnerPollsAction( Owner $owner ) {
|
public function sendOwnerPollsAction( Owner $owner ) {
|
||||||
|
|
||||||
@ -97,6 +102,11 @@ class MailService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Comment $comment
|
||||||
|
*
|
||||||
|
* @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface
|
||||||
|
*/
|
||||||
public function sendCommentNotification( Comment $comment ) {
|
public function sendCommentNotification( Comment $comment ) {
|
||||||
|
|
||||||
$config = [
|
$config = [
|
||||||
@ -106,7 +116,7 @@ class MailService {
|
|||||||
'email_template' => 'emails/comment-notification.html.twig',
|
'email_template' => 'emails/comment-notification.html.twig',
|
||||||
];
|
];
|
||||||
|
|
||||||
return $this->sendMailWithVars( $config );
|
$this->sendMailWithVars( $config );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -139,14 +149,21 @@ class MailService {
|
|||||||
'creation_comment' => 'Framadate | Commentaire de "' . $config[ 'owner' ]->getPseudo() . '" - sondage ' . $config[ 'poll' ]->getTitle(),
|
'creation_comment' => 'Framadate | Commentaire de "' . $config[ 'owner' ]->getPseudo() . '" - sondage ' . $config[ 'poll' ]->getTitle(),
|
||||||
'creation_vote' => 'Framadate | Vote de "' . $config[ 'owner' ]->getPseudo() . '" - sondage ' . $config[ 'poll' ]->getTitle(),
|
'creation_vote' => 'Framadate | Vote de "' . $config[ 'owner' ]->getPseudo() . '" - sondage ' . $config[ 'poll' ]->getTitle(),
|
||||||
];
|
];
|
||||||
|
// Create a message
|
||||||
|
$message = ( new Swift_Message( 'Wonderful Subject' ) )
|
||||||
|
->setFrom( [ 'contact@framadate-api.cipherbliss.com' ] )
|
||||||
|
->setTo( ['contact@cipherbliss.com'] )
|
||||||
|
->setBody( 'Here is the message itself' );
|
||||||
|
|
||||||
$email = ( new TemplatedEmail() )
|
// Send the message
|
||||||
->from( new Address( $config[ 'from' ] ) )
|
$numSent = $this->mailer->send( $message );
|
||||||
// ->setHeaders( [new Header('charset', 'UTF-8' )])
|
printf( "Sent %d messages\n", $numSent );
|
||||||
->subject( $config[ 'title' ] )
|
// $email = ( new TemplatedEmail() )
|
||||||
->to( $config[ 'owner' ]->getEmail() )
|
// ->from( new Address( $config[ 'from' ] ) )
|
||||||
->htmlTemplate( $config[ 'email_template' ] )
|
// ->subject( $config[ 'title' ] )
|
||||||
->context( $config );
|
// ->to( $config[ 'owner' ]->getEmail() )
|
||||||
|
// ->htmlTemplate( $config[ 'email_template' ] )
|
||||||
|
// ->context( $config );
|
||||||
|
|
||||||
|
|
||||||
// $email = ( new \Swift_Mime_SimpleMessage($config[ 'from' ]) )
|
// $email = ( new \Swift_Mime_SimpleMessage($config[ 'from' ]) )
|
||||||
@ -172,7 +189,7 @@ class MailService {
|
|||||||
// ;
|
// ;
|
||||||
|
|
||||||
// send email
|
// send email
|
||||||
return $this->
|
|
||||||
mailer->send( $email );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user