ats / email-bundle
"ATS DIGITAL" Symfony 邮件扩展包。
2.0.0
2019-02-05 17:03 UTC
Requires
- php: >=7.0
- alcaeus/mongo-php-adapter: ^1.1
- ats/core-bundle: dev-master
- doctrine/mongodb-odm: ^1.1.7
- doctrine/mongodb-odm-bundle: ^3.4.0
- symfony/cache: ~3.4.0
- symfony/config: ~3.4.0
- symfony/dependency-injection: ~3.4.0
- symfony/filesystem: ~3.4.0
- symfony/finder: ~3.4.0
- symfony/http-foundation: ~3.4.0
- symfony/http-kernel: ~3.4.0
- symfony/monolog-bundle: ^3.1.0
- symfony/routing: ~3.4.0
- symfony/swiftmailer-bundle: ^3.2
- symfony/templating: ~3.4.0
- symfony/twig-bundle: ~3.4.0
- symfony/yaml: ^3.4
- twig/twig: ^1.0||^2.0
Requires (Dev)
- phpstan/phpstan: ^0.11
- phpstan/phpstan-symfony: ^0.11
- squizlabs/php_codesniffer: ^3.3
- symfony/browser-kit: ~3.4.0
- symfony/css-selector: ~3.4.0
- symfony/debug: ~3.4.0
- symfony/dom-crawler: ~3.4.0
- symfony/framework-bundle: ~3.4.0
- symfony/phpunit-bridge: ~3.4.0
- symfony/process: ~3.4.0
- symfony/var-dumper: ~3.4.0
- symfony/web-server-bundle: ~3.4.0
Provides
- ext-mongo: *
This package is not auto-updated.
Last update: 2021-09-19 20:06:06 UTC
README
通用
- 电子邮件处理扩展包
特性与功能
- SimpleMailerService,它提供了在SwiftMailerBundle之上的覆盖层
- REST端点以发送或重新发送现有电子邮件
- 电子邮件文档类用于文档持久化
设置
1- 更新您的composer.json以添加ATS私有Packagist
{
"repositories": [
{
"type": "composer",
"url": "https://packagist.ats-digital.com"
}
],
}
2- 在您的应用程序中安装扩展包
$ php composer require ats/email-bundle
3- 在AppKernel中注册扩展包
<?php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
// ...
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle(),
new ATS\CoreBundle\ATSCoreBundle(),
new ATS\EmailBundle\ATSEmailBundle(),
// ...
];
}
// ...
}
配置
# Example configuration
ats_email:
api_prefix: 'my-new-api-prefix'
provider: swiftmailer
provider_config:
transport: gmail
username: [email protected]
password: pa$$
注意:当未提供api_prefix
时,将使用默认的(api)代替
用法
- 该扩展包提供了一个SimpleMailerService和一个Email文档类,作为SwiftMailerBundle之上的超级层。然后,发送电子邮件就像从SimpleMailerService类中调用
send()
方法一样简单
// php file
$doSave = false;
$email = new Email();
$email->setTemplate("my-template.html.twig") // template file must be valid and accessible
->setMessageParameters($parameters) // $parameters is an associative array
->setSubject("Email subject")
->setFrom("[email protected]") // Sender's address
->setFromName("John Doe")
->setTo(["[email protected]"])
->setCc(['[email protected]', '[email protected]'])
->setBcc(['[email protected]'])
->setAttatchments(['/path/to/attachment.ext']);
$mailerService = $this->getContainer()->get('ats_email.service.simple_mailer');
$mailerService->send($email, $doSave); // When the $doSave parameter is set to true, the email will be persisted in the DataBase
- 该扩展包还提供了2个端点
POST /%api_prefix%/email/send/{doSave}
当设置为true时,
doSave
参数将在发送电子邮件后将电子邮件保存到数据库中。当设置为false时,控制器操作将只向指定的收件人发送电子邮件。请注意,doSave
默认为false
POST /%api_prefix%/email/resend/{id}
其中
id
是需要重新发送的电子邮件对象的MongId