francescogabbrielli / swift-aws-ses-transport
通过PHP Api v2和v3为Swiftmailer添加AWS SES支持
dev-master
2020-01-03 22:01 UTC
Requires
- php: >=5.4.0
- aws/aws-sdk-php: *
- francescogabbrielli/aws-ses-wrapper: *
- html2text/html2text: ^4.2
- swiftmailer/swiftmailer: >4.1.0
This package is auto-updated.
Last update: 2024-09-04 08:02:33 UTC
README
这是什么?
它是Swiftmailer的一个传输插件,用于通过AWS SES发送邮件。这是jmhobbs使用AWS SesClient v2/v3更新版本的传输插件。目前仍然处于开发状态。欢迎合作/提出想法。
我该把它放在哪里?
最佳使用方式是通过composer。
composer require francescogabbrielli/swift-aws-ses-transport
如果您还没有安装Swiftmailer,它将会自动将其引入。否则,如果您将文件放在这个目录中,Swift可以自动加载它
[swift library root]/classes/Swift/AwsSesTransport.php
我该如何使用它?
就像使用任何其他Swiftmailer传输一样
//Create the desired AWS Transport with the client (for Api v2 do not specify $config_set) //Standard raw email send $transport = Swift_AwsSesTransport::newRawInstance($ses_client, $config_set); //Simple email send (no attachments) $transport = Swift_AwsSesTransport::newFormattedInstance($ses_client, $config_set); //Template email send $transport = Swift_AwsSesTransport::newTemplatedInstance($ses_client, $config_set, $template); ->setReplacementData(TEMPLATE_DATA); //Bulk template email send $transport = Swift_AwsSesTransport::newBulkInstance($ses_client, $config_set, $template) ->setReplacementData(TEMPLATE_DATA) ->addDestination(...) ->addDestination(...) ... ->addDestination(...); //Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); ... $mailer->send($message);
Symfony1.X配置
```yaml
# app/frontend/config/factories.yml
all:
mailer:
class: sfMailer
param:
transport:
class: SwiftAwsSesTransport
```
如何在发送时获取消息ID?
您可以注册一个Swift_Events_ResponseListener插件并设置回调函数。
请参见example/responseListener.php以获取详细信息。它与异步调用结合使用特别有用。
$transport ->setAsync(true) ->registerPlugin( new Swift_Events_ResponseReceivedListener() { public function responseReceived( \Swift_Events_ResponseEvent $evt ) { $response = $evt->getResponse();//Aws\Result $sent = $evt->getSource()->getCount(); echo sprintf( "Message-ID %s.\n", $response->get("MessageId")); } });
对于同步调用,消息ID位于消息的头部
$message->getHeaders()->get("X-SES-Message-ID");
对于批量发送,有一个实用方法可以读取所有发送的消息ID
$transport->getSentMessageIds();
Swiftmailer版本
已在版本5和6上进行了测试。对于版本5,请在AwsSesTransport内部更改方法签名
public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null)
到
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
致谢
- @jmhobbs - 对AWS SES rest API的原始工作:https://github.com/jmhobbs/Swiftmailer-Transport--AWS-SES
- @laravel - 对AWS SES的Swift Transport实现的更新:https://github.com/laravel/framework/tree/5.7/src/Illuminate/Mail/Transport