molnix / bounced-mail-manager
Check for bounced emails and take action on them.
Requires
- php: ^7.1|^8.0
- ddeboer/imap: ^1.12
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.27
This package is auto-updated.
Last update: 2023-11-08 09:10:49 UTC
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 |
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
$messages = (new BounceManager( string $host, string $port = '993', string $username, string $password, string $mailbox = 'INBOX' ))->get()