Installation
composer require azine/email-bundle
Register the bundle in config/bundles.php:
return [
// ...
Azine\EmailBundle\AzineEmailBundle::class => ['all' => true],
Knp\Bundle\PaginatorBundle\KnpPaginatorBundle::class => ['all' => true],
];
Add routes in config/routes.yaml:
azine_email_bundle:
resource: "@AzineEmailBundle/Resources/config/routing.yml"
Configure Swiftmailer
Ensure swiftmailer is configured in config/packages/swiftmailer.yaml (e.g., SMTP or Mailgun).
Set Up Recipient Class
Define your user entity (e.g., App\Entity\User) as the recipient_class in config/packages/azine_email.yaml:
azine_email:
recipient_class: App\Entity\User
no_reply:
email: no-reply@example.com
name: 'Your App'
template_provider: azine_email.example.template_provider # Custom service (see below)
Create a Custom Notifier Service
Extend AzineNotifierService (e.g., src/Service/CustomNotifierService.php) and implement methods like:
public function getVarsForNotificationsEmail() { ... }
public function getRecipientVarsForNotificationsEmail($recipient) { ... }
Register it as a service in config/services.yaml:
services:
App\Service\CustomNotifierService:
tags: ['azine_email.notifier_service']
Send Your First Email
Use the AzineEmailBundle in a controller:
use Azine\EmailBundle\Service\AzineNotifierService;
public function sendWelcomeEmail(User $user)
{
$notifier = $this->container->get('azine_email.notifier_service');
$notifier->sendNotificationEmail($user, 'welcome', ['name' => $user->getName()]);
}
Transactional Emails (Notifications)
sendNotificationEmail() for one-off emails (e.g., password resets, order confirmations).$params array:
$notifier->sendNotificationEmail($user, 'order_confirmation', [
'order_id' => $order->getId(),
'total' => $order->getTotal(),
]);
getRecipientVarsForNotificationsEmail() to customize per-recipient content.Newsletters
sendNewsletter() for bulk emails:
$notifier->sendNewsletter('weekly_update', [
'promo_code' => 'SUMMER20',
]);
getRecipientSpecificNewsletterContentItems() to personalize content.Template Customization
AzineTemplateProvider to modify styles/images:
class CustomTemplateProvider extends AzineTemplateProvider
{
public function getStyles()
{
return [
'header' => 'font-family: Arial; color: #333;',
// Override default styles
];
}
}
config/services.yaml:
services:
azine_email.example.template_provider:
class: App\Service\CustomTemplateProvider
tags: ['azine_email.template_provider']
Tracking and Analytics
email_open_tracking_url in config:
azine_email:
email_open_tracking_url: 'https://your-piwik.com/tracker.php'
{% addCampaignParamsForTemplate link path='utm_source=newsletter' %}
<a href="{{ link }}">Click here</a>
Web Preview
web_view_retention)./azine/email/webview/{id}.WebViewServiceInterface to customize storage/rendering.php bin/console azine:email:send-spooled
RecipientProviderInterface to fetch recipients dynamically (e.g., from a database query).azine_email:
template_twig_swift_mailer:
urgent: azine_email.urgent_mailer
normal: azine_email.default_mailer
swiftmailer:
transport: smtp://mailhog:1025
X-Frame-Options Header
Ensure X-Frame-Options is set to SAMEORIGIN in .htaccess or nginx.conf to avoid iframe errors in the web preview:
Header set X-Frame-Options "SAMEORIGIN"
Image Embedding
Cron Job Dependencies
php bin/console azine:email:send-newsletter --dry-run
Template Caching
php bin/console cache:clear
Doctrine Migrations
notification and sent_email tables:
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
SELECT * FROM notification WHERE status = 'spooled';
/azine/email/preview/{id} to debug HTML/TXT rendering.config/packages/monolog.yaml:
handlers:
swiftmailer:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.swiftmailer.log"
level: debug
Custom Tracking Codes
Extend AzineEmailOpenTrackingCodeBuilder to support custom analytics tools:
class CustomTrackingBuilder implements AzineEmailOpenTrackingCodeBuilderInterface
{
public function buildTrackingCode($emailId, $recipientEmail)
{
return '<img src="https://your-tool.com/track?email=' . $emailId . '" width="1" height="1" />';
}
}
Register it in config/services.yaml:
services:
azine.email.open.tracking.code.builder.custom:
class: App\Service\CustomTrackingBuilder
tags: ['azine_email.email_open_tracking_code_builder']
Override Default Templates
Copy templates from vendor/azine/email-bundle/Azine/EmailBundle/Resources/views/ to templates/azine_email/ to customize without extending the bundle.
Add Custom Email Types
Extend the Notification entity or create a new entity to support additional email categories (e.g., "promotions").
Batch Processing
Use the AzineEmailBundle’s batch API to send emails in chunks:
$notifier->sendBatchNotificationEmail($recipients, 'promotion', $params, 100);
interval in azine_email.newsletter is in days. Set to 0 for immediate sending (not recommended for production).allowed_images_folders to restrict embedded images to specific paths (security):
azine_email:
allowed_images_folders:
- '%kernel.project_dir%/public/uploads/email_images'
no_reply config must include both email and name fields. Omitting either will cause errors.notification and sent_email tablesHow can I help you explore Laravel packages today?