Email System
Doggy's email system is built on Symfony Mailer, supporting multi-mailbox configuration, template management, and async sending.
Overview
Key files:
| File | Description |
|---|---|
src/Service/MailService.php | Email sending service |
src/Service/Security/EmailHtmlSanitizer.php | HTML security filter |
src/Entity/System/EmailConfig.php | Mailbox configuration |
src/Entity/System/EmailTemplate.php | Email template |
src/Entity/System/EmailLog.php | Send log |
src/Entity/System/EmailFunctionBinding.php | Function binding |
Admin controller: App\Controller\Admin\EmailConfigController
Email Templates
Templates are stored in the database (EmailTemplate entity) with visual editing support:
Template directory: templates/admin/email/
editor.html.twig: Template editorindex.html.twig: Template listpreview.html.twig: Template preview
Sending Email
Send via MailService:
php
use App\Service\MailService;
class NotificationService
{
public function __construct(private MailService $mailService) {}
public function sendWelcome(Employee $employee): void
{
$this->mailService->send(
to: $employee->getEmail(),
subject: 'Welcome to Doggy',
template: 'welcome',
params: [
'name' => $employee->getName(),
]
);
}
}HTML Security
EmailHtmlSanitizer filters HTML content before sending:
- Removes
script,iframe,objectand other dangerous elements - XSS injection prevention
- Protects recipient security
Function Binding
EmailFunctionBinding links email capabilities with system events for automated sending:
- Password reset emails
- Account activation notifications
- System alert notifications
Configuration
yaml
# config/packages/mailer.yaml
framework:
mailer:
dsn: '%env(MAILER_DSN)%'