lekoala/silverstripe-mandrill
在 SilverStripe CMS 中添加 Mandrill
Requires
- php: >=8.1
- composer/ca-bundle: ^1.1
- silverstripe/framework: ^5
- silverstripe/recipe-plugin: ^2
- silverstripe/vendor-plugin: ^2
- symbiote/silverstripe-gridfieldextensions: ^4.0
- symfony/http-client: ^5.4|^6.0
- symfony/mailchimp-mailer: ^6.3
Requires (Dev)
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.5
README
在 SilverStripe 中使用 Mandrill
在您的 .env 文件中定义以下常量
MANDRILL_API_KEY='YOUR_API_KEY_HERE'
或通过在您的 config.yml 中定义 API 密钥
LeKoala\Mandrill\MandrillHelper: mandrill_api_key: "key3goes9here"
此模块使用官方 php sdk 版本 1.0.54,并做了一些调整。
您还可以使用以下常量在您的 .env 文件中自动配置模块
# Will log emails in the temp folders
MANDRILL_ENABLE_LOGGING=true
# Will disable sending (useful in development)
MANDRILL_SENDING_DISABLED=true
# Set app domain explicitly
MANDRILL_DOMAIN="mysite.co.nz"
# Also recommended to specify an explicit from
SS_SEND_ALL_EMAILS_FROM="noreply@mysite.co.nz"
通过定义 API 密钥,模块将注册一个新的邮件发送器,用于发送所有邮件。
集成
此模块创建一个新的管理员部分,允许您直接从 SilverStripe CMS 中查看 API 调用的结果,而无需登录到 mandrillapp.com。
Webhooks
从 Mandrill 管理员界面,您可以为您网站设置一个 webhook。此 webhook 将被调用,MandrillController 将负责处理所有事件。
默认情况下,MandrillController 不会执行任何操作。您可以根据需要向 MandrillController 添加自己的扩展,以定义自己的规则,例如“当收到垃圾邮件投诉时,向管理员发送电子邮件”。
MandrillController 提供了 4 个扩展点
- updateHandleAnyEvent
- updateHandleSyncEvent
- updateHandleInboundEvent
- updateHandleMessageEvent
建议您确保请求来自 Mailchimp 交易,而不是模仿者。默认情况下,Webhook 认证被禁用,但您可以通过配置层启用 Webhook 认证,如下所示
LeKoala\Mandrill\MandrillController:
webhook_auth_enabled: true
您需要您的 Webhook 认证密钥,您可以在您的账户中的(Webhooks)[https://mandrillapp.com/settings/webhooks] 页面上查看和重置。使用配置层或 .env
文件添加您的密钥。
通过配置
LeKoala\Mandrill\MandrillController:
webhook_key: YOUR_KEY
通过 .env 文件
MANDRILL_WEBHOOK_KEY=YOUR_KEY
从 Swift Mailer 迁移
SilverStripe 5 用 symfony/mailer 替换了 swift mailer
请务必阅读文档 https://docs.silverstripe.org/en/5/developer_guides/email/ https://symfony.ac.cn/doc/current/mailer.html
对于 SS4 版本,请检查分支 3 和 v4 版本
兼容性
已测试与 SilverStripe 5+
维护者
LeKoala - thomas@lekoala.be