spatie/laravel-mailcoach-mailgun-setup
Prepares a Mailgun account to work with Mailcoach by configuring/processing feedback for email campaigns. Intended for internal use by Mailcoach; usable independently but no official docs or support beyond Mailcoach documentation.
Installation
composer require spatie/laravel-mailcoach-mailgun-setup
Publish the config file:
php artisan vendor:publish --provider="Spatie\MailcoachMailgunSetup\MailcoachMailgunSetupServiceProvider"
Configuration
Edit .env with your Mailgun API credentials:
MAILGUN_DOMAIN=your-domain.mailgun.org
MAILGUN_SECRET_KEY=your-api-key
First Use Case Run the setup command to configure Mailgun for Mailcoach:
php artisan mailcoach:mailgun:setup
This creates:
mail.yourdomain.com).Pre-Campaign Setup
mailcoach:mailgun:setup once after Mailcoach installation.mail.yourdomain.com) is added to Mailgun’s Domains tab.Campaign-Specific Actions
Webhook Handling
/mailcoach/webhooks/mailgun.Spatie\MailcoachMailgunSetup\WebhookHandler to customize event processing (e.g., logging, analytics).Domain Management
Use MailcoachMailgunSetup::createTrackingDomain() to dynamically add domains:
$domain = MailcoachMailgunSetup::createTrackingDomain('mail.yourdomain.com');
Route Configuration
Register custom Mailgun routes via MailcoachMailgunSetup::addRoute():
MailcoachMailgunSetup::addRoute('campaigns/{campaignId}/opens', 'post');
Event Listeners
Listen for mailcoach.mailgun.webhook.received to process events:
Event::listen('mailcoach.mailgun.webhook.received', function ($event) {
// Custom logic (e.g., update CRM)
});
Webhook Verification
.env has:
MAILGUN_WEBHOOK_SECRET=your-unique-secret
DNS Configuration
mail.yourdomain.com) must have:
mailgun.org (or your Mailgun subdomain).dig TXT yourdomain.com to verify records.Rate Limits
Idempotency
Webhook Failures
Enable debug logging in config/mailcoach-mailgun-setup.php:
'debug' => env('MAILGUN_DEBUG', false),
Check storage/logs/laravel.log for webhook payloads.
Command Errors
Run with --verbose:
php artisan mailcoach:mailgun:setup --verbose
Custom Webhook Logic Override the webhook handler:
// app/Providers/AppServiceProvider.php
public function boot()
{
$this->app->bind(
\Spatie\MailcoachMailgunSetup\WebhookHandler::class,
\App\CustomMailgunWebhookHandler::class
);
}
Dynamic Domain Setup Extend the setup command to fetch domains from a database:
// app/Console/Commands/SetupMailgun.php
protected function getTrackingDomains()
{
return Domain::where('is_tracking', true)->pluck('name')->toArray();
}
Event Dispatching Dispatch custom events after webhook processing:
Event::dispatch(new MailgunEventProcessed($event->payload));
How can I help you explore Laravel packages today?