Flow Swiftmailer 5.4 Documentation¶
This package allows to easily use the Swift Mailer library with Flow applications.
This version of the documentation covering release 5.4.1 has been rendered at: Mar 29, 2017
The package can be installed via composer:
composer require typo3/swiftmailer
To set up the mail transport to be used, adjust the settings as needed. Without any further
configuration, mails will be sent using
Swift_MailTransport which uses the PHP
function. To use SMTP for sending, follow the following example:
TYPO3: SwiftMailer: transport: type: 'Swift_SmtpTransport' options: host: 'smtp.example.com' port: '465' username: 'email@example.com' password: 'shoobidoo' localDomain: 'example.com'
Further transports are available with Swift Mailer and can be used as well. Their options can
be looked up the Swift Mailer documentation and they can be set by extrapolating from their
setter method names (as in:
username in the options.)
If a transport is configured, sending mail is as simple as this:
- create new
- set your sender address with
- set a subject line with
- set recipients with
- set a body with
- add attachments with
- send with
Here is an example:
$mail = new \Neos\SwiftMailer\Message(); $mail ->setFrom(array($senderAddress => $senderName)) ->setTo(array($recipientAddress => $recipientName)) ->setSubject($subject); $mail->setBody($message, 'text/html'); $mail->setBody($message, 'text/plain'); $mail->send();
Debugging sent mail¶
To debug sent mails, an easy way is to configure the transport to the the mbox handler of this package. If this is done in a context-specific configuration (for Development or a sub-context on a staging server), it can be safely committed to a VCS:
Neos: SwiftMailer: transport: type: 'Neos\SwiftMailer\Transport\MboxTransport' options: mboxPathAndFilename: '%FLOW_PATH_DATA%/Persistent/sent-mail'
All sent mails will be added to the configured mbox file and can be read with any client that can handle the mbox file format.
A second option is to use the
LoggingTransport, which logs all mails to the SystemLog
Neos: SwiftMailer: transport: type: 'Neos\SwiftMailer\Transport\LoggingTransport'