3 namespace Wallabag\UserBundle\Mailer
;
5 use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface
;
6 use Scheb\TwoFactorBundle\Mailer\AuthCodeMailerInterface
;
7 use Symfony\Component\Translation\TranslatorInterface
;
10 * Custom mailer for TwoFactorBundle email.
11 * It adds a custom template to the email so user won't get a lonely authentication code but a complete email.
13 class AuthCodeMailer
implements AuthCodeMailerInterface
23 * Twig to render the html's email.
25 * @var \Twig_Environment
30 * Sender email address.
44 * Support URL to report any bugs.
51 * Initialize the auth code mailer with the SwiftMailer object.
53 * @param \Swift_Mailer $mailer
54 * @param \Twig_Environment $twig
55 * @param string $senderEmail
56 * @param string $senderName
57 * @param string $supportUrl
59 public function __construct(\Swift_Mailer
$mailer, \Twig_Environment
$twig, $senderEmail, $senderName, $supportUrl)
61 $this->mailer
= $mailer;
63 $this->senderEmail
= $senderEmail;
64 $this->senderName
= $senderName;
65 $this->supportUrl
= $supportUrl;
69 * Send the auth code to the user via email.
71 * @param TwoFactorInterface $user
73 public function sendAuthCode(TwoFactorInterface
$user)
75 $template = $this->twig
->loadTemplate('@WallabagUserBundle/Resources/views/TwoFactor/email_auth_code.html.twig');
77 $subject = $template->renderBlock('subject', array());
78 $bodyHtml = $template->renderBlock('body_html', [
79 'user' => $user->getName(),
80 'code' => $user->getEmailAuthCode(),
81 'support' => $this->supportUrl
,
83 $bodyText = $template->renderBlock('body_text', [
84 'user' => $user->getName(),
85 'code' => $user->getEmailAuthCode(),
86 'support' => $this->supportUrl
,
89 $message = new \
Swift_Message();
91 ->setTo($user->getEmail())
92 ->setFrom($this->senderEmail
, $this->senderName
)
93 ->setSubject($subject)
94 ->setBody($bodyText, 'text/plain')
95 ->addPart($bodyHtml, 'text/html')
98 $this->mailer
->send($message);