|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tempest\Mail\Transports\Ses; |
| 4 | + |
| 5 | +use Symfony\Component\Mailer\Bridge\Amazon\Transport\SesApiAsyncAwsTransport; |
| 6 | +use Symfony\Component\Mailer\Bridge\Amazon\Transport\SesHttpAsyncAwsTransport; |
| 7 | +use Symfony\Component\Mailer\Bridge\Amazon\Transport\SesSmtpTransport; |
| 8 | +use Symfony\Component\Mailer\Bridge\Amazon\Transport\SesTransportFactory; |
| 9 | +use Symfony\Component\Mailer\Transport\Dsn; |
| 10 | +use Symfony\Component\Mailer\Transport\NullTransport; |
| 11 | +use Symfony\Component\Mailer\Transport\TransportInterface; |
| 12 | +use Tempest\Mail\Address; |
| 13 | +use Tempest\Mail\MailerConfig; |
| 14 | +use UnitEnum; |
| 15 | + |
| 16 | +/** |
| 17 | + * Send emails using Amazon SES. |
| 18 | + */ |
| 19 | +final class SesMailerConfig implements MailerConfig |
| 20 | +{ |
| 21 | + public string $transport { |
| 22 | + get => match ($this->sceme) { |
| 23 | + Scheme::API => SesApiAsyncAwsTransport::class, |
| 24 | + Scheme::HTTP => SesHttpAsyncAwsTransport::class, |
| 25 | + }; |
| 26 | + } |
| 27 | + |
| 28 | + public function __construct( |
| 29 | + /** |
| 30 | + * Access key used for authenticating to the SES API. |
| 31 | + */ |
| 32 | + public string $accessKey, |
| 33 | + |
| 34 | + /** |
| 35 | + * Secret key used for authenticating to the SES API. |
| 36 | + */ |
| 37 | + public string $secretKey, |
| 38 | + |
| 39 | + /** |
| 40 | + * Region configured in your SES account. |
| 41 | + */ |
| 42 | + public string $region, |
| 43 | + |
| 44 | + /** |
| 45 | + * An optional endpoint to use instead of the default one. |
| 46 | + */ |
| 47 | + public ?string $host = null, |
| 48 | + |
| 49 | + /** |
| 50 | + * An optional Amazon SES session token. |
| 51 | + */ |
| 52 | + public ?string $sessionToken = null, |
| 53 | + |
| 54 | + /** |
| 55 | + * Address from which emails are sent by default. |
| 56 | + */ |
| 57 | + public null|string|Address $from = null, |
| 58 | + |
| 59 | + /** |
| 60 | + * Whether to use Amazon SES's API or async HTTP transport. |
| 61 | + */ |
| 62 | + public Scheme $scheme = Scheme::HTTP, |
| 63 | + |
| 64 | + /* |
| 65 | + * Identifies the {@see \Tempest\Mail\Mailer} instance in the container, in case you need more than one configuration. |
| 66 | + */ |
| 67 | + public null|string|UnitEnum $tag = null, |
| 68 | + ) {} |
| 69 | + |
| 70 | + public function createTransport(): TransportInterface |
| 71 | + { |
| 72 | + return new SesTransportFactory()->create(new Dsn( |
| 73 | + scheme: $this->scheme->value, |
| 74 | + user: $this->accessKey, |
| 75 | + password: $this->secretKey, |
| 76 | + host: $this->host ?? 'default', |
| 77 | + options: [ |
| 78 | + 'region' => $this->region, |
| 79 | + 'session_token' => $this->sessionToken, |
| 80 | + ], |
| 81 | + )); |
| 82 | + } |
| 83 | +} |
0 commit comments