3 namespace Wallabag\UserBundle\Mailer
;
5 use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface
;
6 use Scheb\TwoFactorBundle\Mailer\AuthCodeMailerInterface
;
7 use Symfony\Component\Translation\DataCollectorTranslator
;
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 * Translator for email content.
25 * @var DataCollectorTranslator
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 DataCollectorTranslator $translator
55 * @param string $senderEmail
56 * @param string $senderName
57 * @param string $supportUrl
59 public function __construct(\Swift_Mailer
$mailer, DataCollectorTranslator
$translator, $senderEmail, $senderName, $supportUrl)
61 $this->mailer
= $mailer;
62 $this->translator
= $translator;
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 $message = new \
Swift_Message();
77 ->setTo($user->getEmail())
78 ->setFrom($this->senderEmail
, $this->senderName
)
79 ->setSubject($this->translator
->trans('auth_code.mailer.subject', array(), 'wallabag_user'))
80 ->setBody($this->translator
->trans(
81 'auth_code.mailer.body',
83 '%user%' => $user->getName(),
84 '%code%' => $user->getEmailAuthCode(),
85 '%support%' => $this->supportUrl
,
91 $this->mailer
->send($message);