Install the Bundle
composer require 2lenet/hermes-bundle
Ensure your project uses Symfony Mailer (HermesBundle depends on it).
Configure Symfony Mailer
Add transport configuration in config/packages/mailer.yaml (Symfony) or bridge it to Laravel’s config/mail.php using spatie/laravel-symfony-mailer.
Enable the Bundle
Register in config/bundles.php (Symfony) or create a Laravel service provider to bootstrap HermesBundle’s services.
First Use Case: Send a Templated Email Use the CruditBundle admin panel to create an email template (via the dashboard) or trigger it programmatically:
// Example using Symfony's DI (adapt for Laravel)
$mailer = $container->get('hermes.mailer');
$mailer->send('template_name', ['user' => $user]);
Verify the Dashboard
Access /admin/hermes (default route) to manage templates, recipients, and sent emails.
Pattern: Use Twig templates stored in templates/hermes/ (default location).
Laravel Adaptation: Mount Twig templates in Laravel’s resources/views/vendor/hermes/ and configure the template path in HermesBundle’s config.
Example:
{# templates/hermes/welcome.twig #}
<h1>Welcome, {{ user.name }}!</h1>
<p>Your account is now active.</p>
Trigger via Code:
// Symfony (adapt for Laravel)
$mailer = $this->get('hermes.mailer');
$mailer->send('welcome', ['user' => $user], ['to' => $user->email]);
['newsletter' => [$user1, $user2]]).MailRecipient entities to track sent emails, statuses (sent, failed, etc.), and unsubscribes.$recipient = new MailRecipient();
$recipient->setEmail($user->email);
$recipient->setStatus(MailRecipient::STATUS_SENT);
$entityManager->persist($recipient);
['marketing' => [$email1, $email2]]) for segmented campaigns.$mailer->send('newsletter', [], [
'cc' => ['marketing' => ['user1@example.com', 'user2@example.com']],
]);
Pattern: Save emails as drafts in the database and send them later.
Example:
$mail = new Mail();
$mail->setTemplate('welcome');
$mail->setVariables(['user' => $user]);
$mail->setStatus(Mail::STATUS_DRAFT);
$entityManager->persist($mail);
Send Later:
$mail->setStatus(Mail::STATUS_PENDING);
$mail->setSentAt(new \DateTime('+1 day')); // Schedule for tomorrow
$mailer->send('invoice', ['user' => $user], [
'attachments' => [
new \Symfony\Component\Mime\Part\FilePart('path/to/invoice.pdf'),
],
]);
{# templates/hermes/welcome.twig #}
<h1>{{ 'welcome.title'|trans }}</h1>
config/packages/translation.yaml (Symfony) or Laravel’s config/app.php.Service Provider Bridge: Create a Laravel service provider to register HermesBundle’s services:
// app/Providers/HermesServiceProvider.php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Symfony\Component\DependencyInjection\ContainerInterface;
class HermesServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton('hermes.mailer', function ($app) {
return new \Hermes\Mailer\Mailer(
$app['symfony.mailer.transport'],
$app['hermes.template.manager']
);
});
}
}
Twig Integration:
Use tightenco/jigsaw or spatie/laravel-twig-view to render Twig templates in Laravel:
// config/services.php
'twig' => [
'paths' => [
resource_path('views/vendor/hermes'),
],
],
Queue Support: Extend HermesBundle to use Laravel’s queues for async sending:
// app/Console/Commands/SendHermesEmails.php
namespace App\Console\Commands;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Console\Command;
use Hermes\Mailer\Mailer;
class SendHermesEmails extends Command
{
use InteractsWithQueue, SerializesModels;
protected $mailer;
public function __construct(Mailer $mailer)
{
$this->mailer = $mailer;
}
public function handle()
{
$this->mailer->sendQueuedEmails();
}
}
Database Migrations: Adapt HermesBundle’s Doctrine entities to Laravel’s Eloquent:
// app/Models/Mail.php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Mail extends Model
{
const STATUS_DRAFT = 'draft';
const STATUS_SENT = 'sent';
// ...
}
Use spatie/laravel-symfony-mailer to integrate Symfony Mailer into Laravel:
composer require spatie/laravel-symfony-mailer
Configure in config/mail.php:
'driver' => env('MAIL_DRIVER', 'symfony'),
'symfony' => [
'dsn' => env('MAIL_SYMFONY_DSN', 'null://localhost'),
],
CruditBundle Dependency:
Template Path Configuration:
templates/hermes/. In Laravel, this may not exist.# config/packages/hermes.yaml (Symfony)
hermes:
template_dir: '%kernel.project_dir%/resources/views/vendor/hermes'
Or in Laravel’s config:
// config/hermes.php
return [
'template_dir' => resource_path('views/vendor/hermes'),
];
Symfony Mailer vs. Laravel Mail:
Mail::send().// app/Facades/Hermes.php
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class Hermes extends Facade
{
protected static function getFacadeAccessor()
{
return 'hermes.mailer';
}
}
Entity Manager Conflicts:
EntityManager. In Laravel, this may conflict with Eloquent.How can I help you explore Laravel packages today?