3 namespace Wallabag\UserBundle\Mailer
;
5 use Scheb\TwoFactorBundle\Mailer\AuthCodeMailerInterface
;
6 use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface
;
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.
30 * Sender email address.
44 * Support URL to report any bugs.
51 * Url for the wallabag instance (only used for image in the HTML email template).
58 * Initialize the auth code mailer with the SwiftMailer object.
60 * @param \Swift_Mailer $mailer
61 * @param Environment $twig
62 * @param string $senderEmail
63 * @param string $senderName
64 * @param string $supportUrl wallabag support url
65 * @param string $wallabagUrl wallabag instance url
67 public function __construct(\Swift_Mailer
$mailer, Environment
$twig, $senderEmail, $senderName, $supportUrl, $wallabagUrl)
69 $this->mailer
= $mailer;
71 $this->senderEmail
= $senderEmail;
72 $this->senderName
= $senderName;
73 $this->supportUrl
= $supportUrl;
74 $this->wallabagUrl
= $wallabagUrl;
78 * Send the auth code to the user via email.
80 * @param TwoFactorInterface $user
82 public function sendAuthCode(TwoFactorInterface
$user): void
84 $template = $this->twig
->loadTemplate('WallabagUserBundle:TwoFactor:email_auth_code.html.twig');
86 $subject = $template->renderBlock('subject', []);
87 $bodyHtml = $template->renderBlock('body_html', [
88 'user' => $user->getName(),
89 'code' => $user->getEmailAuthCode(),
90 'support_url' => $this->supportUrl
,
91 'wallabag_url' => $this->wallabagUrl
,
93 $bodyText = $template->renderBlock('body_text', [
94 'user' => $user->getName(),
95 'code' => $user->getEmailAuthCode(),
96 'support_url' => $this->supportUrl
,
99 $message = new \
Swift_Message();
101 ->setTo($user->getEmailAuthRecipient())
102 ->setFrom($this->senderEmail
, $this->senderName
)
103 ->setSubject($subject)
104 ->setBody($bodyText, 'text/plain')
105 ->addPart($bodyHtml, 'text/html')
108 $this->mailer
->send($message);