mirror of
https://github.com/wallabag/wallabag.git
synced 2025-06-27 16:36:00 +00:00
Use built in FOSUserBundle mailer
This commit is contained in:
parent
47d3bd4b69
commit
c9301bd0b3
4 changed files with 1 additions and 94 deletions
|
@ -197,7 +197,7 @@ fos_user:
|
|||
address: "%from_email%"
|
||||
sender_name: wallabag
|
||||
service:
|
||||
mailer: Wallabag\Mailer\UserMailer
|
||||
mailer: fos_user.mailer.twig_symfony
|
||||
|
||||
fos_oauth_server:
|
||||
db_driver: orm
|
||||
|
|
|
@ -260,16 +260,6 @@ services:
|
|||
$defaultSettings: '%wallabag.default_internal_settings%'
|
||||
$defaultIgnoreOriginInstanceRules: '%wallabag.default_ignore_origin_instance_rules%'
|
||||
|
||||
Wallabag\Mailer\UserMailer:
|
||||
arguments:
|
||||
$parameters:
|
||||
template:
|
||||
confirmation: '%fos_user.registration.confirmation.template%'
|
||||
resetting: '%fos_user.resetting.email.template%'
|
||||
from_email:
|
||||
confirmation: '%fos_user.registration.confirmation.from_email%'
|
||||
resetting: '%fos_user.resetting.email.from_email%'
|
||||
|
||||
Wallabag\Event\Listener\CreateConfigListener:
|
||||
arguments:
|
||||
$itemsOnPage: "%wallabag.items_on_page%"
|
||||
|
|
|
@ -60,11 +60,6 @@ parameters:
|
|||
count: 2
|
||||
path: src/Mailer/AuthCodeMailer.php
|
||||
|
||||
-
|
||||
message: "#^PHPDoc type Symfony\\\\Component\\\\Mailer\\\\MailerInterface of property Wallabag\\\\Mailer\\\\UserMailer\\:\\:\\$mailer is not covariant with PHPDoc type Swift_Mailer of overridden property FOS\\\\UserBundle\\\\Mailer\\\\TwigSwiftMailer\\:\\:\\$mailer\\.$#"
|
||||
count: 1
|
||||
path: src/Mailer/UserMailer.php
|
||||
|
||||
-
|
||||
message: "#^Call to an undefined method DOMNode\\:\\:getAttribute\\(\\)\\.$#"
|
||||
count: 1
|
||||
|
|
|
@ -1,78 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Wallabag\Mailer;
|
||||
|
||||
use FOS\UserBundle\Mailer\TwigSwiftMailer;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
use Symfony\Component\Mime\Address;
|
||||
use Symfony\Component\Mime\Email;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
* This replace the default mailer from TwigSwiftMailer by symfony/mailer instead of swiftmailer.
|
||||
*/
|
||||
class UserMailer extends TwigSwiftMailer
|
||||
{
|
||||
/**
|
||||
* @var MailerInterface
|
||||
*/
|
||||
protected $mailer;
|
||||
|
||||
/**
|
||||
* @var UrlGeneratorInterface
|
||||
*/
|
||||
protected $router;
|
||||
|
||||
/**
|
||||
* @var Environment
|
||||
*/
|
||||
protected $twig;
|
||||
|
||||
/**
|
||||
* @var array{template: array{confirmation: string, resetting: string}, from_email: array{confirmation: array<string, string>|string, resetting: array<string, string>|string}}
|
||||
*/
|
||||
protected $parameters;
|
||||
|
||||
public function __construct(MailerInterface $mailer, UrlGeneratorInterface $router, Environment $twig, array $parameters)
|
||||
{
|
||||
$this->mailer = $mailer;
|
||||
$this->router = $router;
|
||||
$this->twig = $twig;
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $templateName
|
||||
* @param array $context
|
||||
* @param array $fromEmail
|
||||
* @param string $toEmail
|
||||
*/
|
||||
protected function sendMessage($templateName, $context, $fromEmail, $toEmail)
|
||||
{
|
||||
$template = $this->twig->load($templateName);
|
||||
$subject = $template->renderBlock('subject', $context);
|
||||
$textBody = $template->renderBlock('body_text', $context);
|
||||
|
||||
$htmlBody = '';
|
||||
|
||||
if ($template->hasBlock('body_html', $context)) {
|
||||
$htmlBody = $template->renderBlock('body_html', $context);
|
||||
}
|
||||
|
||||
$email = (new Email())
|
||||
->from(new Address(key($fromEmail), current($fromEmail)))
|
||||
->to($toEmail)
|
||||
->subject($subject);
|
||||
|
||||
if (!empty($htmlBody)) {
|
||||
$email
|
||||
->text($textBody)
|
||||
->html($htmlBody);
|
||||
} else {
|
||||
$email->text($textBody);
|
||||
}
|
||||
|
||||
$this->mailer->send($email);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue