Skip to content

Commit c61154d

Browse files
committed
feature symfony#45404 [Mailer] allow custom hosts for ses+smtp with amazon mailer (jrushlow)
This PR was merged into the 6.2 branch. Discussion ---------- [Mailer] allow custom hosts for ses+smtp with amazon mailer | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Specifically allows the use of VPC Endpoints without the need for Private DNS on EC2. Commits ------- 599bee1 [Mailer] allow custom hosts for ses+smtp with amazon mailer
2 parents c3288f6 + 599bee1 commit c61154d

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add support for `X-SES-MESSAGE-TAGS`
8+
* Add support for custom ses+smtp hosts
89

910
6.0
1011
---

src/Symfony/Component/Mailer/Bridge/Amazon/Tests/Transport/SesTransportFactoryTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ public function createProvider(): iterable
156156
new Dsn('ses+smtps', 'default', self::USER, self::PASSWORD, null, ['region' => 'eu-west-1', 'ping_threshold' => '10']),
157157
(new SesSmtpTransport(self::USER, self::PASSWORD, 'eu-west-1', $dispatcher, $logger))->setPingThreshold(10),
158158
];
159+
160+
yield [
161+
new Dsn('ses+smtp', 'custom.vpc.endpoint', self::USER, self::PASSWORD, null, ['region' => 'eu-west-1']),
162+
new SesSmtpTransport(self::USER, self::PASSWORD, 'eu-west-1', $dispatcher, $logger, 'custom.vpc.endpoint'),
163+
];
164+
165+
yield [
166+
new Dsn('ses+smtps', 'custom.vpc.endpoint', self::USER, self::PASSWORD, null, ['region' => 'eu-west-1']),
167+
new SesSmtpTransport(self::USER, self::PASSWORD, 'eu-west-1', $dispatcher, $logger, 'custom.vpc.endpoint'),
168+
];
159169
}
160170

161171
public function unsupportedSchemeProvider(): iterable

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +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)
31+
public function __construct(string $username, #[\SensitiveParameter] string $password, string $region = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null, string $host = 'default')
3232
{
33-
parent::__construct(sprintf('email-smtp.%s.amazonaws.com', $region ?: 'eu-west-1'), 465, true, $dispatcher, $logger);
33+
if ('default' === $host) {
34+
$host = sprintf('email-smtp.%s.amazonaws.com', $region ?: 'eu-west-1');
35+
}
36+
37+
parent::__construct($host, 465, true, $dispatcher, $logger);
3438

3539
$this->setUsername($username);
3640
$this->setPassword($password);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function create(Dsn $dsn): TransportInterface
3030
$region = $dsn->getOption('region');
3131

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

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

0 commit comments

Comments
 (0)