sunaoka/laravel-ses-template-driver
Composer 安装命令:
composer require sunaoka/laravel-ses-template-driver
包简介
Amazon SES template mail driver for Laravel.
README 文档
README
A Mail Driver with support for Using templates to send personalized emails with the Amazon SES API.
Support Policy
| Version (*1) | Laravel (*2) | PHP (*3) |
|---|---|---|
| 1 | 5.7 - 6 | 7.1 - 7.4 |
| 2 | 7 - 8 | 7.2 - 8.1 |
| 3 | 9 - 11 | 8.0 - 8.4 |
| 4 | 10 - 13 | 8.1 - 8.5 |
(*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', 'TenantName' => 'MyTenant', // using Amazon SES API v2 with AWS SDK for PHP 3.352.0 or later '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": "*"
}
]
}
Reference
sunaoka/laravel-ses-template-driver 适用场景与选型建议
sunaoka/laravel-ses-template-driver 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 94.08k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2019 年 01 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mail」 「aws」 「driver」 「laravel」 「ses」 「sesv2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sunaoka/laravel-ses-template-driver 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sunaoka/laravel-ses-template-driver 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sunaoka/laravel-ses-template-driver 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package includes a script and fail2ban configuration that allows you to use fail2ban when utilizing AWS elastic load balancer (ELB) and an apache webserver.
Elastic Driver for Laravel Scout
Galera cluster driver for Doctrine
simple api library.
Courier offers a convenient and painless solution for creating emails tailored for your Kirby website.
A PHP client driver for the RethinkDB query language (ReQL)
统计信息
- 总下载量: 94.08k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-01-23