sunaoka / laravel-ses-template-driver
Amazon SES template mail driver for Laravel.
Installs: 58 431
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 4
Forks: 1
Open Issues: 0
Requires
- php: ^8.1
- ext-json: *
- ext-mbstring: *
- aws/aws-sdk-php: ^3.245.0
- illuminate/console: ^10.0 || ^11.0
- illuminate/mail: ^10.0 || ^11.0
Requires (Dev)
- larastan/larastan: ^2.9.11 || ^3.0.0
- laravel/pint: ^1.18.2
- orchestra/testbench: ^8.28.0 || ^v9.6.1
- dev-develop
- v4.2.0
- v4.1.1
- v4.1.0
- dev-main / 4.0.x-dev
- v4.0.0
- v3.x-dev
- v3.4.0
- v3.3.1
- v3.3.0
- v3.2.0
- v3.1.0
- v3.0.1
- v3.0.0
- v2.x-dev
- v2.2.0
- v2.1.0
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.x-dev
- v1.5.0
- v1.4.0
- v1.3.5
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.0
- v1.1.1
- v1.1.0
- v1.0.1
- v1.0.0
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
This package is auto-updated.
Last update: 2024-12-12 01:57:22 UTC
README
A Mail Driver with support for Using templates to send personalized emails with the Amazon SES API.
Support Policy
(*1) Supported Amazon SES template mail driver (This Driver) version
(*2) Supported Laravel versions
(*3) Supported PHP versions
Installation
composer require sunaoka/laravel-ses-template-driver
Next, set the following in config/mail.php
and config/services.php
.
config/mail.php
'default' => 'sestemplate', 'mailers' => [ 'sestemplate' => [ 'transport' => 'sestemplate', // or `sesv2template` - When using Amazon SES API v2 ], ],
config/services.php
'ses' => [ 'key' => 'your-ses-key', 'secret' => 'your-ses-secret', 'region' => 'ses-region', // e.g. us-east-1 ],
If you need to include additional options when executing the SES SendTemplatedEmail
request, you may define an options
array within your ses
configuration:
'ses' => [ 'key' => 'your-ses-key', 'secret' => 'your-ses-secret', 'region' => 'ses-region', // e.g. us-east-1 'options' => [ 'ConfigurationSetName' => 'MyConfigurationSet', 'Tags' => [ [ 'Name' => 'foo', 'Value' => 'bar', ], ], ], ],
Basic usage
use Illuminate\Support\Facades\Mail; use Sunaoka\LaravelSesTemplateDriver\Mail\SesTemplate; class Foo { public function sendmail() { $templateName = 'MyTemplate'; $templateData = [ 'name' => 'Alejandro', 'favoriteanimal' => 'alligator', ]; $result = Mail::to('alejandro.rosalez@example.com') ->cc('cc@example.com') ->bcc('bcc@example.com') ->send(new SesTemplate($templateName, $templateData)); echo $result->getMessageId(); // Message-ID overwritten by Amazon SES } }
Options
Set From
, Reply-To
and custom header.
use Illuminate\Mail\Mailables\Address; use Illuminate\Support\Facades\Mail; use Sunaoka\LaravelSesTemplateDriver\Mail\SesTemplate; use Sunaoka\LaravelSesTemplateDriver\Mail\SesTemplateOptions; class Foo { public function sendmail() { $templateName = 'MyTemplate'; $templateData = [ 'name' => 'Alejandro', 'favoriteanimal' => 'alligator', ]; $options = new SesTemplateOptions(); $options->from(new Address('alejandro.rosalez@example.com', 'Alejandro Rosalez')) ->replyTo(new Address('alejandro.rosalez@example.com')); // Only with Amazon SES API v2 ('transport' is `sesv2template`) $options->header('X-Custom-Header1', 'Custom Value 1') ->header('X-Custom-Header2', 'Custom Value 2'); // You can also set it in the constructor. $options = new SesTemplateOptions( from: new Address('alejandro.rosalez@example.com', 'Alejandro Rosalez'), replyTo: new Address('alejandro.rosalez@example.com'), headers: [ 'X-Custom-Header1' => 'Custom Value 1', 'X-Custom-Header2' => 'Custom Value 2', ], ); $result = Mail::to('alejandro.rosalez@example.com') ->cc('cc@example.com') ->bcc('bcc@example.com') ->send(new SesTemplate($templateName, $templateData, $options)); echo $result->getMessageId(); // Message-ID overwritten by Amazon SES } }
To send a templated email to a single destination
{ "Template": { "TemplateName": "MyTemplate", "SubjectPart": "Greetings, {{name}}!", "HtmlPart": "<h1>Hello {{name}},</h1><p>Your favorite animal is {{favoriteanimal}}.</p>", "TextPart": "Dear {{name}},\r\nYour favorite animal is {{favoriteanimal}}." } }
Not supported, to send a templated email to multiple destinations.
Artisan Console Commands
Lists the email templates present in your Amazon SES account in the current AWS Region.
Options
php artisan ses-template:list-templates --help
Description:
Lists the email templates present in your Amazon SES account in the current AWS Region
Usage:
ses-template:list-templates [options]
Options:
--name Sort by the name of the template [default]
--time Sort by the time and date the template was created
--asc Sort by ascending order [default]
--desc Sort by descending order
--json The output is formatted as a JSON string
Output Text format
php artisan ses-template:list-templates
+----+-------------+---------------------------+
| No | Name | Created At |
+----+-------------+---------------------------+
| 0 | MyTemplate | 2020-11-24T15:01:21+00:00 |
| 1 | MyTemplate2 | 2020-11-24T15:01:25+00:00 |
+----+-------------+---------------------------+
Enter a number to display the template object:
> 0
TemplateName:
MyTemplate
SubjectPart:
Greetings, {{name}}!
TextPart:
Dear {{name}},\r\nYour favorite animal is {{favoriteanimal}}.
HtmlPart:
<h1>Hello {{name}},</h1><p>Your favorite animal is {{favoriteanimal}}.</p>
Output JSON format
php artisan ses-template:list-templates --json
{ "TemplatesMetadata": [ { "Name": "MyTemplate", "CreatedTimestamp": "2020-11-24T15:01:21+00:00" }, { "Name": "MyTemplate2", "CreatedTimestamp": "2020-11-24T15:01:25+00:00" } ] }
Amazon SES API v2
{ "TemplatesMetadata": [ { "TemplateName": "MyTemplate", "CreatedTimestamp": "2020-11-24T15:01:21+00:00" }, { "TemplateName": "MyTemplate2", "CreatedTimestamp": "2020-11-24T15:01:25+00:00" } ] }
Displays the template object for the template you specify
Options
php artisan ses-template:get-template --help
Description:
Displays the template object for the template you specify
Usage:
ses-template:get-template [options] [--] <TemplateName>
Arguments:
TemplateName The name of the template to retrieve
Options:
--json The output is formatted as a JSON string
Output Text format
php artisan ses-template:get-template MyTemplate
TemplateName:
MyTemplate
SubjectPart:
Greetings, {{name}}!
TextPart:
Dear {{name}},\r\nYour favorite animal is {{favoriteanimal}}.
HtmlPart:
<h1>Hello {{name}},</h1><p>Your favorite animal is {{favoriteanimal}}.</p>
Output JSON format
php artisan ses-template:get-template MyTemplate --json
{ "Template": { "TemplateName": "MyTemplate", "SubjectPart": "Greetings, {{name}}!", "HtmlPart": "<h1>Hello {{name}},</h1><p>Your favorite animal is {{favoriteanimal}}.</p>", "TextPart": "Dear {{name}},\r\nYour favorite animal is {{favoriteanimal}}." } }
Amazon SES API v2
{ "Template": { "TemplateName": "MyTemplate", "TemplateContent": { "Subject": "Greetings, {{name}}!", "Html": "<h1>Hello {{name}},</h1><p>Your favorite animal is {{favoriteanimal}}.</p>", "Text": "Dear {{name}},\r\nYour favorite animal is {{favoriteanimal}}." } } }
AWS Identity and Access Management (IAM) Policy
Amazon SES API (v1)
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ses:SendTemplatedEmail", "ses:ListTemplates", "ses:GetTemplate" ], "Resource": "*" } ] }
Amazon SES API v2
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ses:SendEmail", "ses:ListEmailTemplates", "ses:GetEmailTemplate" ], "Resource": "*" } ] }