Installation
composer require appventus/spoolmailerbundle
Add to config/bundles.php:
AppVentus\AvSpoolMailerBundle\AvSpoolMailerBundle::class => ['all' => true],
Configure
Update config/packages/av_awesome_spool_mailer.yaml (or merge into config/packages/swiftmailer.yaml):
av_awesome_spool_mailer:
contact_addresses:
admin:
address: admin@example.com
name: Admin Team
noreply:
address: noreply@example.com
name: NoReply System
First Use Case Queue an email in a controller:
use Symfony\Component\DependencyInjection\ContainerInterface;
public function sendWelcomeEmail(ContainerInterface $container, $userEmail)
{
$message = (new \Swift_Message('Welcome'))
->setFrom($container->getParameter('contact_addresses_noreply_address'), $container->getParameter('contact_addresses_noreply_name'))
->setTo($userEmail)
->setBody('Hello!');
$container->get('spool_mailer')->queueMessage($message);
}
Spooling Emails
spool_mailer service to queue emails for later sending:
$spoolMailer = $this->get('spool_mailer');
$spoolMailer->queueMessage($swiftMessage);
Sending Instant Emails
instant_mailer for time-sensitive emails (e.g., password resets):
$instantMailer = $this->get('instant_mailer');
$instantMailer->send($swiftMessage);
Bulk Sending
php bin/console swiftmailer:spool:send
SwiftMailer Integration
Swift_Message objects with metadata (e.g., tags for Mailgun):
$message->setHeader('X-Tag', 'welcome_series');
Doctrine ORM
Resources/config/doctrine/SpoolMailer.Message.orm.yml if needed.Parameter Bag Access
$adminEmail = $this->getParameter('contact_addresses_admin_address');
Event Listeners
spool.mailer.queue or spool.mailer.send events (Symfony 2.x style) for logging/auditing.Deprecated Bundle
Console Command Quirks
swiftmailer:spool:send may fail silently if the spool table is empty. Add logging:
# config/packages/monolog.yaml
handlers:
spool_mailer:
type: stream
path: "%kernel.logs_dir%/spool_mailer.log"
level: debug
Parameter Bag Naming
contact_addresses_admin_address). Typos will cause ParameterNotFoundException.Transaction Safety
$entityManager->flush(); // Commit first
$spoolMailer->queueMessage($message);
Check Spool Table
av_spool_mailer_message for stuck emails:
SELECT * FROM av_spool_mailer_message WHERE sent_at IS NULL;
SwiftMailer Debugging
config/packages/swiftmailer.yaml:
transport: "%env(MAILER_DSN)%"
spool: { type: memory } # Temporarily switch to memory spool for debugging
Event Dispatching
# config/services.yaml
services:
App\Service\DebugSpoolMailer:
decorates: spool_mailer
arguments: ['@spool_mailer']
Custom Spool Table
Resources/config/doctrine/ to add fields (e.g., user_id for tracking):
AppVentus\AvSpoolMailerBundle\Entity\Message:
type: entity
table: custom_spool_emails
fields:
userId:
type: integer
Pre-Send Hooks
instant_mailer to validate emails before sending:
$instantMailer->send($message); // Add validation logic here
Alternative Transport
swiftmailer:
transport: gmail
spool: { type: db, table: av_spool_mailer_message }
How can I help you explore Laravel packages today?