提交 2e9ccd00 编写于 作者: 伟伟权

103. symfony/mailer and mailcatcher send/receive mail

上级 a38b4b86
......@@ -32,3 +32,7 @@ DATABASE_URL="mysql://root:password@127.0.0.1:8888/teebblog?serverVersion=5.7"
# postgresql+advisory://db_user:db_password@localhost/db_name
LOCK_DSN=semaphore
###< symfony/lock ###
###> symfony/mailer ###
MAILER_DSN=smtp://127.0.0.1:1025
###< symfony/mailer ###
......@@ -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": "ac64afcdeeb644bb67981c8d2e989526",
"content-hash": "15f43f40b7427a91aa25d3687fb76654",
"packages": [
{
"name": "composer/package-versions-deprecated",
......@@ -1636,6 +1636,80 @@
],
"time": "2021-07-06T18:33:30+00:00"
},
{
"name": "egulias/email-validator",
"version": "3.1.1",
"source": {
"type": "git",
"url": "https://github.com/egulias/EmailValidator.git",
"reference": "c81f18a3efb941d8c4d2e025f6183b5c6d697307"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/egulias/EmailValidator/zipball/c81f18a3efb941d8c4d2e025f6183b5c6d697307",
"reference": "c81f18a3efb941d8c4d2e025f6183b5c6d697307",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"doctrine/lexer": "^1.2",
"php": ">=7.2",
"symfony/polyfill-intl-idn": "^1.15"
},
"require-dev": {
"php-coveralls/php-coveralls": "^2.2",
"phpunit/phpunit": "^8.5.8|^9.3.3",
"vimeo/psalm": "^4"
},
"suggest": {
"ext-intl": "PHP Internationalization Libraries are required to use the SpoofChecking validation"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.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/3.1.1"
},
"funding": [
{
"url": "https://github.com/egulias",
"type": "github"
}
],
"time": "2021-04-01T18:37:14+00:00"
},
{
"name": "fakerphp/faker",
"version": "v1.15.0",
......@@ -4749,6 +4823,87 @@
],
"time": "2021-06-06T09:51:56+00:00"
},
{
"name": "symfony/mailer",
"version": "v5.3.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/mailer.git",
"reference": "6ebd500f14402344fe4369ee88bfec27a567a24d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/mailer/zipball/6ebd500f14402344fe4369ee88bfec27a567a24d",
"reference": "6ebd500f14402344fe4369ee88bfec27a567a24d",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"egulias/email-validator": "^2.1.10|^3",
"php": ">=7.2.5",
"psr/log": "~1.0",
"symfony/deprecation-contracts": "^2.1",
"symfony/event-dispatcher": "^4.4|^5.0",
"symfony/mime": "^5.2.6",
"symfony/polyfill-php80": "^1.15",
"symfony/service-contracts": "^1.1|^2"
},
"conflict": {
"symfony/http-kernel": "<4.4"
},
"require-dev": {
"symfony/http-client-contracts": "^1.1|^2",
"symfony/messenger": "^4.4|^5.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/v5.3.3"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2021-06-24T08:13:00+00:00"
},
{
"name": "symfony/mime",
"version": "v5.3.2",
......
framework:
mailer:
dsn: '%env(MAILER_DSN)%'
......@@ -15,6 +15,11 @@ parameters:
- 'world'
- 'abc'
support_locales: en|zh_CN|fr
send_email: admin@teebblog.com
editor_email: editor@teebblog.com
checker_email: checker@teebblog.com
services:
# default configuration for services in *this* file
_defaults:
......
<?php
namespace App\EventSubscriber;
use App\Entity\Post;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use \EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityPersistedEvent;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
class SendEmailSubscrberSubscriber implements EventSubscriberInterface
{
/**
* @var ParameterBagInterface
*/
private ParameterBagInterface $parameterBag;
/**
* @var MailerInterface
*/
private MailerInterface $mailer;
public function __construct(ParameterBagInterface $parameterBag, MailerInterface $mailer)
{
$this->parameterBag = $parameterBag;
$this->mailer = $mailer;
}
public function onAfterEntityPersistedEvent(AfterEntityPersistedEvent $event)
{
$post = $event->getEntityInstance();
if ($post instanceof Post)
{
$email = (new Email())
->from($this->parameterBag->get('send_email'))
->to($this->parameterBag->get('editor_email'), $this->parameterBag->get('checker_email'))
->subject('有新的文章<'.$post->getTitle().'>发布了,请检查。')
->text('有新的文章<'.$post->getTitle().'>发布了,请检查。');
sleep(10);
$this->mailer->send($email);
}
}
public static function getSubscribedEvents()
{
return [
AfterEntityPersistedEvent::class => 'onAfterEntityPersistedEvent',
];
}
}
......@@ -109,6 +109,9 @@
"ref": "b131e6cbfe1b898a508987851963fff485986285"
}
},
"egulias/email-validator": {
"version": "3.1.1"
},
"fakerphp/faker": {
"version": "v1.15.0"
},
......@@ -422,6 +425,18 @@
"config/packages/lock.yaml"
]
},
"symfony/mailer": {
"version": "4.3",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "4.3",
"ref": "15658c2a0176cda2e7dba66276a2030b52bd81b2"
},
"files": [
"config/packages/mailer.yaml"
]
},
"symfony/maker-bundle": {
"version": "1.0",
"recipe": {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册