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 04, 2019
The package can be installed via composer:
composer require neos/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_SendmailTransport which uses
on the server. To adjust the sendmail command, you can use:
Neos: SwiftMailer: transport: type: 'Swift_SendmailTransport' options: command: '/usr/sbin/sendmail -bs'
To use SMTP for sending, follow the following example:
Neos: SwiftMailer: transport: type: 'Swift_SmtpTransport' options: host: 'smtp.example.com' port: '465' encryption: 'ssl' username: 'firstname.lastname@example.org' password: 'shoobidoo' localDomain: 'example.com'
The encryption property supports values
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.)
Swift_MailTransport that was available in the past has been removed with the Swift
Mailer library 6.0 release, see https://github.com/swiftmailer/swiftmailer/issues/866 for
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'