molnix/bounced-mail-manager
Composer 安装命令:
composer require molnix/bounced-mail-manager
包简介
Check for bounced emails and take action on them.
README 文档
README
A package can read IMAP and parse mails to check if they are bounced emails. When used with laravel, can notifiy the original sender.
Installation:
composer require molnix/bounced-mail-manager
Add the custom headers created by the getCustomHeaders method to outgoing mails.
Molnix\BouncedMailManager\Message\Header::getCustomHeaders( string $sender, // Sender email to send notificaitons string $sentTo, // send to email string $subject ='' optional subject ): array
Laravel
Package can be customized with optional env variables
| Variable | Description |
|---|---|
BOUNCEMAIL_HOST |
IMAP host url, default: MAIL_HOST from .env |
BOUNCEMAIL_PORT |
IMAP port, default: 993 |
BOUNCEMAIL_USERNAME |
IMAP username, default: MAIL_USERNAME from .env |
BOUNCEMAIL_PASSWORD |
IMAP password, default: MAIL_PASSWORD from .env |
BOUNCEMAIL_MAILBOX |
Mailox name, default: INBOX |
BOUNCEMAIL_DELETE_MODE |
False will use read/unread instead of deleting, default: true |
BOUNCEMAIL_TYPE |
Mailbox type: null. imap,o365 , default: imap |
BOUNCEMAIL_OAUTH_CLIENT_ID |
Oauth client id , default: null |
BOUNCEMAIL_OAUTH_SECRET |
Oauth secret , default: null |
BOUNCEMAIL_AZURE_TENANT_ID |
Azure tenant id if using office 365 , default: null |
Configuration
The package will automatically register a service provider. You can publish for further customization.
| Tag | Description |
|---|---|
config |
Configuration |
views |
Notification email markdown |
translations |
Bounce reason translations |
Optionally publish files if further customization is required.
php artisan vendor:publish --provider="Molnix\BouncedMailManager\BounceManagerServiceProvider" --tag="config" php artisan vendor:publish --provider="Molnix\BouncedMailManager\BounceManagerServiceProvider" --tag="views" php artisan vendor:publish --provider="Molnix\BouncedMailManager\BounceManagerServiceProvider" --tag="translations"
Usage
Use Molnix\BouncedMailManager\Traits\BounceMailHeaders trait in Mailable to add headers to outgoing headers.
Option 1: With setup
// PostMail use BounceMailHeaders; public function __construct(Comment $comment) { $this->comment = $comment; $this->setupBounceManager(); } public function build(){ $this->subject('Comment added') ->markdown('emails.comment') ->addBounceManagerHeaders(); }
Option 2: Without setup
// PostMail use BounceMailHeaders; public function __construct(Comment $comment, $sender) { $this->comment = $comment; $this->sender = $sender; } public function build(){ $this->subject('Comment added') ->markdown('emails.comment') ->addBounceManagerHeaders($this->sender); }
Add this command to the scheduler.
php artisan bouncemanager:run
PHP
- #### Create instance ```php use Molnix\BouncedMailManager\BounceManager; $manager = new BounceManager( 'imap.example.com', '993', 'wind@example.com', 'emailpassword', string $mailbox = 'INBOX', array $options = [] // extra optional options );
or
use Molnix\BouncedMailManager\BounceManager; use Molnix\BouncedMailManager\Clients\ImapClient; $manager->setClient(new ImapClient( 'imap.example.com', '993', 'wind@example.com', 'emailpassword', string $mailbox = 'INBOX', array $options = [] // extra optional options ));
or Office 365 way
use Molnix\BouncedMailManager\BounceManager; use Molnix\BouncedMailManager\Clients\O365Client; $manager = new BounceManager(); $manager->setClient(new O365Client('wind@example.com', $tenant_id, $client_id, $client_secret));
$manager->setMailbox('OtherMailbBoxName');
// Use -1 for all mails. $manager->setDaysFrom(10); // Since last 10 days
-
Set how to handle processed email management. Default is to mark the mail as seen. To use delete after process:
$manager->enableDeleteMode(); // Since last 10 days
$manager->toArray(); // Returns simple array of bounces. $manager->get(); // Returns array of bounces objects.
Setup office 365 mailbox.
The setup needed to be done in two section,
- Azure web portal
- Powershell
Azure web portal
-
Setup Permissions, Click on
API permissions->APIs my organization usestab -> serachOffice 365 Exchange Online->Application permissions->IMAP.AccessAsApp
Powershell
Run these commands in powershell in order one by one. Remember to replace values for $AppId with Application (client) ID, $TenantId with Directory (tenant) ID. These can be found in the app page in azure web. Your email ID with the mailbox email you grant access to.
Install-Module -Name AzureAD Install-Module -Name ExchangeOnlineManagement $AppId = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" $TenantId = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" Import-module AzureAD Connect-AzureAd -Tenant $TenantId ($Principal = Get-AzureADServicePrincipal -filter "AppId eq '$AppId'") $PrincipalId = $Principal.ObjectId $DisplayName = "Bounce manager IMAP Access" Import-module ExchangeOnlineManagement Connect-ExchangeOnline -Organization $TenantId New-ServicePrincipal -AppId $AppId -ServiceId $PrincipalId -DisplayName $DisplayName Add-MailboxPermission -User $PrincipalId -AccessRights FullAccess -Identity "Your email ID"
Usage
use Molnix\BouncedMailManager\BounceManager; use Molnix\BouncedMailManager\Clients\O365; $manager = new BounceManager(); $manager->setClient(new O365('wind@example.com', $tenant_id, $client_id, $client_secret)); $manager->get();
molnix/bounced-mail-manager 适用场景与选型建议
molnix/bounced-mail-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.21k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2023 年 09 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「email」 「bounce」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 molnix/bounced-mail-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 molnix/bounced-mail-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 molnix/bounced-mail-manager 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Bounce Mail Handler
Symfony bundle to monitor AWS SES bounces and complaints. Includes SwiftMailer filters.
Extensible library for building notifications and sending them via different delivery channels.
Email+ extends Kirby's email capabilities by adding support for multiple email services using the same Kirby email API.
PHP class to help webmasters handle bounce-back, feedback loop and ARF mails in standard DSN (Delivery Status Notification, RFC-1894).
Laravel contact us form package to send email and save to database
统计信息
- 总下载量: 1.21k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-27