Mail is a component which allow to create/send email easily whatever mailer mecanism you use (SwiftMailer...).
Installation
Using Composer, just require the ddd/components package:
{
"require": {
"ddd/components": "dev-master"
}
}Usage
1. Prepare your email
Method A
<?php
use Ddd\Mail\Model\TextMail;
use Ddd\Mail\Model\Contact;
use Ddd\Mail\Infra\Mailer\SwiftMailer;
use Ddd\Mail\Infra\Mailer\AmazonSesMailer;
$mail = new TextMail(new Contact('support@github.com', 'Github'));
$mail
->compose('[Github] Payment receipt', 'Here my body formatted in Text format')
->addRecipient(new Contact('customer1@gmail.com'))
->addRecipient(new Contact('customer2@gmail.com', 'Customer 2'))
;Method B
<?php
use Ddd\Mail\MailBuilder;
use Ddd\Mail\Infra\Mailer\SwiftMailer;
use Ddd\Mail\Infra\Mailer\AmazonSesMailer;
$mail = MailBuilder::create('support@github.com', 'Github')
->compose('[Github] Payment receipt', 'Here my body formatted in Text format')
->addRecipients(array(
'customer1@gmail.com',
'customer2@gmail.com' => 'Customer 2'
))
->getTextMail()
;2. Send it###
With Mail you can send your emails with the mailer of your choice (SwiftMailer, Amazon SES, Compain monitor...):
$mail->send(new SwiftMailer($container->get('swift_mailer'))); // Send email with SwiftMailer.
$mail->send(new AmazonSesMailer($container->get('aws.ses.client'))); // Send same email with Amazon SES.Icebox
- As a user, I should be able to create a sendable basic email with very simple API.
-
As a user, I should be able to send basic
TextMailwith SwiftMailer asMailerInterfaceimplementation. -
As a user, I should be able to send basic
TextMailwith "Amazon SES" asMailerInterfaceimplementation. - [ ][Chore] As a user, I'm expecting when any error occured, a
MailerExceptionshould be thrown whatever implementation used. - As a user, I should be able to create a mail without knowing any domain object.
- As a user, I could give as recipient a group of contacts that will enable "Newsletter" mode.
-
As a user, I could be able to send basic
HtmlEmailwith SwiftMailer. -
As a user, I could add attachments to
HtmlEmailANDTextEmail. - As a user, I could give copy carbon recipient.
- As a user, I could give blind copy carbon recipient.
- As a user, a contact should always be valid.
- As a user, I should be able to change default UTF-8 encoding.
-
As a user, I should be able to send basic
TextMailwith "Compaign Monitor" asMailerInterfaceimplementation. -
As a user, when I put HTML content as body in a
TextMailthe content should be strip of all HTML tags. -
As a user, when I put HTML content as body in an
HtmlMailthe plain text version should be generated automatically. - As a Amazon SES user, I should be able to put special characters in headers (To:, From: etc.).
Credits
- Joseph Rouff rouffj@gmail.com