ats / email-bundle
The "ATS DIGITAL" Symfony Email bundle.
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
General
- Email handler Bundle
Features & Capabilities
- SimpleMailerService the provides an overlay above the SwiftMailerBundle
- ReST end-points to send an email or resend an existing one
- Email document class for document persistence
Setup
1- Update your composer.json to add ATS private packagist:
{
"repositories": [
{
"type": "composer",
"url": "https://packagist.ats-digital.com"
}
],
}
2- Install the bundle in your application
$ php composer require ats/email-bundle
3- Register the bundle in the 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(),
// ...
];
}
// ...
}
Configuration
# Example configuration
ats_email:
api_prefix: 'my-new-api-prefix'
provider: swiftmailer
provider_config:
transport: gmail
username: username@mail.com
password: pa$$
Note: When the api_prefix
is not given, a default (api) will be used instead
Usage
- The bundle provides a SimpleMailerService and an Email document class as a super layer above the SwiftMailerBundle. Sending an email is then as simple as calling the
send()
method method from the SimpleMailerService class
// 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("sender@my-company.com") // Sender's address
->setFromName("John Doe")
->setTo(["recipient@whatever.com"])
->setCc(['copy@me.com', 'metoo@me.com'])
->setBcc(['blindCopy@me.com'])
->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
- The bundle also provides 2 end-points:
POST /%api_prefix%/email/send/{doSave}
When set to true, the
doSave
parameter will save the email into the database after sending the email. When set to false, the controller action will only send an email to the specified recepient. Note thatdoSave
defaults tofalse
POST /%api_prefix%/email/resend/{id}
Where
id
is the MongId of the email object that needs to be resent