diff --git a/app/config/packages/mailer.yaml b/app/config/packages/mailer.yaml new file mode 100644 index 000000000..9db210404 --- /dev/null +++ b/app/config/packages/mailer.yaml @@ -0,0 +1,3 @@ +framework: + mailer: + dsn: 'smtp://%env(SMTP_USERNAME)%:%env(SMTP_PASSWORD)%@%env(SMTP_HOST)%:%env(SMTP_PORT)%' diff --git a/app/config/services.yml b/app/config/services.yml index 7aca371bf..905affb40 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -122,10 +122,8 @@ services: $mailchimp: '@app.mailchimp_api' $listId: "%mailchimp_members_list%" - AppBundle\Email\Mailer\Adapter\MailerAdapter: - class: AppBundle\Email\Mailer\Adapter\PhpMailerAdapter - factory: [AppBundle\Email\Mailer\Adapter\PhpMailerAdapter, createFromConfiguration] - arguments: ['@Afup\Site\Utils\Configuration'] + AppBundle\Email\Mailer\Adapter\SymfonyMailerAdapter: ~ + AppBundle\Email\Mailer\Adapter\MailerAdapter: '@AppBundle\Email\Mailer\Adapter\SymfonyMailerAdapter' AppBundle\Mailchimp\EventEventSubscriber: arguments: diff --git a/composer.json b/composer.json index 14761a361..46cd02cf4 100644 --- a/composer.json +++ b/composer.json @@ -53,6 +53,7 @@ "symfony/http-kernel": "7.3.*", "symfony/intl": "7.3.*", "symfony/lock": "7.3.*", + "symfony/mailer": "^7.4", "symfony/mime": "7.3.*", "symfony/monolog-bundle": "^3.1", "symfony/runtime": "7.4.*", diff --git a/composer.lock b/composer.lock index b10a6bddf..63709904d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a55bcfd2a0998e8ea473bd3f6dc52e40", + "content-hash": "524bbeb8a23ade79e14184cf973af389", "packages": [ { "name": "algolia/algoliasearch-client-php", @@ -2051,6 +2051,73 @@ }, "time": "2019-08-06T09:24:58+00:00" }, + { + "name": "egulias/email-validator", + "version": "4.0.4", + "source": { + "type": "git", + "url": "https://github.com/egulias/EmailValidator.git", + "reference": "d42c8731f0624ad6bdc8d3e5e9a4524f68801cfa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/d42c8731f0624ad6bdc8d3e5e9a4524f68801cfa", + "reference": "d42c8731f0624ad6bdc8d3e5e9a4524f68801cfa", + "shasum": "" + }, + "require": { + "doctrine/lexer": "^2.0 || ^3.0", + "php": ">=8.1", + "symfony/polyfill-intl-idn": "^1.26" + }, + "require-dev": { + "phpunit/phpunit": "^10.2", + "vimeo/psalm": "^5.12" + }, + "suggest": { + "ext-intl": "PHP Internationalization Libraries are required to use the SpoofChecking validation" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Egulias\\EmailValidator\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Eduardo Gulias Davis" + } + ], + "description": "A library for validating emails against several RFCs", + "homepage": "https://github.com/egulias/EmailValidator", + "keywords": [ + "email", + "emailvalidation", + "emailvalidator", + "validation", + "validator" + ], + "support": { + "issues": "https://github.com/egulias/EmailValidator/issues", + "source": "https://github.com/egulias/EmailValidator/tree/4.0.4" + }, + "funding": [ + { + "url": "https://github.com/egulias", + "type": "github" + } + ], + "time": "2025-03-06T22:45:56+00:00" + }, { "name": "ekino/newrelic-bundle", "version": "dev-patch-1", @@ -7439,6 +7506,90 @@ ], "time": "2025-09-11T10:12:26+00:00" }, + { + "name": "symfony/mailer", + "version": "v7.4.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/mailer.git", + "reference": "b02726f39a20bc65e30364f5c750c4ddbf1f58e9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/mailer/zipball/b02726f39a20bc65e30364f5c750c4ddbf1f58e9", + "reference": "b02726f39a20bc65e30364f5c750c4ddbf1f58e9", + "shasum": "" + }, + "require": { + "egulias/email-validator": "^2.1.10|^3|^4", + "php": ">=8.2", + "psr/event-dispatcher": "^1", + "psr/log": "^1|^2|^3", + "symfony/event-dispatcher": "^6.4|^7.0|^8.0", + "symfony/mime": "^7.2|^8.0", + "symfony/service-contracts": "^2.5|^3" + }, + "conflict": { + "symfony/http-client-contracts": "<2.5", + "symfony/http-kernel": "<6.4", + "symfony/messenger": "<6.4", + "symfony/mime": "<6.4", + "symfony/twig-bridge": "<6.4" + }, + "require-dev": { + "symfony/console": "^6.4|^7.0|^8.0", + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/messenger": "^6.4|^7.0|^8.0", + "symfony/twig-bridge": "^6.4|^7.0|^8.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Mailer\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Helps sending emails", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/mailer/tree/v7.4.6" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2026-02-25T16:50:00+00:00" + }, { "name": "symfony/mime", "version": "v7.3.4", diff --git a/sources/AppBundle/Email/Mailer/Adapter/SymfonyMailerAdapter.php b/sources/AppBundle/Email/Mailer/Adapter/SymfonyMailerAdapter.php new file mode 100644 index 000000000..280250d67 --- /dev/null +++ b/sources/AppBundle/Email/Mailer/Adapter/SymfonyMailerAdapter.php @@ -0,0 +1,54 @@ +getFrom(); + if (!$from instanceof MailUser) { + throw new UnexpectedValueException('Trying to send a mail with no sender'); + } + + $email = (new Email()) + ->from(new Address($from->getEmail(), $from->getName())) + ->subject($message->getSubject()) + ->html($message->getContent()); + + foreach ($message->getRecipients() as $mailUser) { + $email->addTo(new Address($mailUser->getEmail(), $mailUser->getName())); + } + + foreach ($message->getCc() as $mailUser) { + $email->addCc(new Address($mailUser->getEmail(), $mailUser->getName())); + } + + foreach ($message->getBcc() as $mailUser) { + $email->addBcc(new Address($mailUser->getEmail(), $mailUser->getName())); + } + + foreach ($message->getAttachments() as $attachment) { + $email->attachFromPath( + $attachment->getPath(), + $attachment->getName(), + $attachment->getType(), + ); + } + + $this->mailer->send($email); + } +}