Skip to content

Commit 65d3bcb

Browse files
adarsnicolas-grekas
authored andcommitted
[Mailer] Allow configuring port and tls options when using the Amazon SES bridge
1 parent 34dae00 commit 65d3bcb

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

src/Symfony/Component/Mailer/Bridge/Amazon/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.4
5+
---
6+
7+
* Add support for configuring the port and tls options
8+
49
7.3
510
---
611

src/Symfony/Component/Mailer/Bridge/Amazon/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Configuration example:
77

88
```env
99
# SMTP
10-
MAILER_DSN=ses+smtp://USERNAME:PASSWORD@default?region=REGION&session_token=SESSION_TOKEN
10+
MAILER_DSN=ses+smtp://USERNAME:PASSWORD@default:PORT?region=REGION&session_token=SESSION_TOKEN
1111
1212
# HTTP
1313
MAILER_DSN=ses+https://ACCESS_KEY:SECRET_KEY@default?region=REGION&session_token=SESSION_TOKEN
@@ -21,6 +21,7 @@ where:
2121
- `SECRET_KEY` is your Amazon SES access key secret
2222
- `REGION` is Amazon SES selected region (optional, default `eu-west-1`)
2323
- `SESSION_TOKEN` is your Amazon SES session token (optional)
24+
- `PORT` is the port you want to communicate to SES with (optional, default `465`)
2425

2526
Resources
2627
---------

src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesSmtpTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ class SesSmtpTransport extends EsmtpTransport
2828
/**
2929
* @param string|null $region Amazon SES region
3030
*/
31-
public function __construct(string $username, #[\SensitiveParameter] string $password, ?string $region = null, ?EventDispatcherInterface $dispatcher = null, ?LoggerInterface $logger = null, string $host = 'default')
31+
public function __construct(string $username, #[\SensitiveParameter] string $password, ?string $region = null, ?EventDispatcherInterface $dispatcher = null, ?LoggerInterface $logger = null, string $host = 'default', ?int $port = 465, ?bool $tls = true)
3232
{
3333
if ('default' === $host) {
3434
$host = \sprintf('email-smtp.%s.amazonaws.com', $region ?: 'eu-west-1');
3535
}
3636

37-
parent::__construct($host, 465, true, $dispatcher, $logger);
37+
parent::__construct($host, $port, $tls, $dispatcher, $logger);
3838

3939
$this->setUsername($username);
4040
$this->setPassword($password);

src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesTransportFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ public function create(Dsn $dsn): TransportInterface
2828
{
2929
$scheme = $dsn->getScheme();
3030
$region = $dsn->getOption('region');
31+
$port = $dsn->getPort() ?? 465;
32+
$tls = $dsn->getOption('tls');
3133

3234
if ('ses+smtp' === $scheme || 'ses+smtps' === $scheme) {
33-
$transport = new SesSmtpTransport($this->getUser($dsn), $this->getPassword($dsn), $region, $this->dispatcher, $this->logger, $dsn->getHost());
35+
$transport = new SesSmtpTransport($this->getUser($dsn), $this->getPassword($dsn), $region, $this->dispatcher, $this->logger, $dsn->getHost(), $port, $tls);
3436

3537
if (null !== $pingThreshold = $dsn->getOption('ping_threshold')) {
3638
$transport->setPingThreshold((int) $pingThreshold);

src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ public function __construct(string $host = 'localhost', int $port = 0, ?bool $tl
5555
$stream = $this->getStream();
5656

5757
if (null === $tls) {
58-
if (465 === $port) {
58+
if (\in_array($port, [465, 2465], true)) {
5959
$tls = true;
60+
} elseif (\in_array($port, [25, 587, 2587], true)) {
61+
$tls = false;
6062
} else {
6163
$tls = \defined('OPENSSL_VERSION_NUMBER') && 0 === $port && 'localhost' !== $host;
6264
}

0 commit comments

Comments
 (0)