Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions Classes/Transport/FdMailerTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Symfony\Component\Mailer\SentMessage;
use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mailer\Transport\TransportInterface;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\RawMessage;

class FdMailerTransport implements TransportInterface
Expand All @@ -35,15 +34,17 @@ public function send(RawMessage $message, ?Envelope $envelope = null): ?SentMess
protected function getActualTransportDsn(): string
{
$config = $this->settings['smtpTransport'] ?? null;
if ($config === null) {
if (!is_array($config)) {
throw new \Exception('Missing FormatD.Mailer settings.');
}

if (!($config['host'] ?? null)) {
throw new \Exception('Missing configuration: FormatD.Mailer.smtpTransport.host');
}

$scheme = ($config['encryption'] ?? false) ? 'smtps' : 'smtp';
$useTlsChannel = $config['encryption'] ?? null;
$useTlsChannel = (bool)($useTlsChannel === 'false' ? false : $useTlsChannel);
$scheme = $useTlsChannel ? 'smtps' : 'smtp';

$credentials = '';
if (($config['username'] ?? null) && ($config['password'] ?? null)) {
Expand All @@ -53,7 +54,12 @@ protected function getActualTransportDsn(): string
$host = $config['host'];
$port = ($config['port'] ?? null) ? ':' . $config['port'] : '';

return $scheme . '://' . $credentials . $host . $port;
$query = '';
if (is_array($config['options'] ?? null)) {
$query = http_build_query($config['options'], '', '&');
}

return $scheme . '://' . $credentials . $host . $port . ($query ? '?' . $query : '');
}

public function __toString(): string
Expand Down
38 changes: 30 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ Releases und compatibility:

| Package-Version | Neos Flow Version | `neos/form` Version |
|-----------------|-------------------|---------------------|
| 2.0.0 | >= 8.x | >= 6.0.0 |
| 2.0.x | >= 8.x | >= 6.0.0 |
| 1.1.x | >= 6.x | < 6.0.0 |
| 1.0.x | 4.x - 5.x | < 6.0.0 |

## Using the service in you own plugins to use fluid templates for mails
## Using the service in your own plugins to use fluid templates for mails

Configure default from address:

Expand Down Expand Up @@ -88,6 +88,9 @@ Use the special DSN `fd-mailer` in the SymfonyMailer configuration. This transpo
given under `FormatD.Mailer.smtpTransport` to build the actual DSN and actual SmtpTransport object. `host` is mandatory,
all other parts are optional.

For special cases the automatic DSN construction can be omitted by passing the DSN directly at
`Neos.SymfonyMailer.mailer.dsn`.

```
Neos:
SymfonyMailer:
Expand All @@ -97,9 +100,28 @@ Neos:
FormatD:
Mailer:
smtpTransport:
host: ''
encryption: ''
port: ''
username: ''
password: ''
```
host: '%env:SMTP_HOST%'
encryption: '%env:SMTP_ENCRYPTION%'
port: '%env:SMTP_PORT%'
username: '%env:SMTP_USERNAME%'
password: '%env:SMTP_PASSWORD%'

# Optional: Query params appended to the DSN, use with caution and only when necessary
options:
# Do not verify server TLS certificate
verify_peer: 0
# Do not try `STARTTLS` at all
auto_tls: 'false'
# Use `STARTTLS` even when not announced in server capabilities
require_tls: 'true'

```

The `encryption` param is cast to boolean, with the `'false'` string being interpreted falsy as well. If true, the
scheme will be `smtps`, thus the Symfony SMTP transport tries to establish a TLS encrypted channel right away. If
`encryption` is false, then the transport will still try to upgrade the connection via `STARTTLS`, when that is
announced by the server!

The `options` config is completely optional and could be omitted to use SymfonyMailer's sane defaults. It can be used to
define query parameters appended to the DSN, as described in
the [SymfonyMailer documentation](https://symfony.com/doc/current/mailer.html).
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"neos/fluid-adaptor": "^8.3"
},
"suggest": {},
"conflict": {
"neos/swiftmailer": "*"
},
"autoload": {
"psr-4": {
"FormatD\\Mailer\\": "Classes/"
Expand Down