symfonymailer
Genere un email Symfony (TemplatedEmail ou Notification) avec template Twig
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Genere un email Symfony (TemplatedEmail ou Notification) avec template Twig
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Audite un projet API Platform existant et produit un rapport de bonnes pratiques, performances et sécurité
Génère des DTOs (input/output) API Platform avec mapping vers les entités
Génère des filtres API Platform (search, date, range, order, boolean, exists, custom)
Génère un State Processor API Platform pour personnaliser la persistence des données
Génère un State Provider API Platform pour personnaliser la récupération de données
Génère une API Resource complète avec attribut
| name | symfony:mailer |
| description | Genere un email Symfony (TemplatedEmail ou Notification) avec template Twig |
| model | sonnet |
| allowed-tools | ["AskUserQuestion","Bash","Read","Write","Edit","Grep","Glob"] |
| version | 1.0.0 |
| license | MIT |
Genere un service d'envoi d'email Symfony avec TemplatedEmail et template Twig associe, ou une Notification multicanal.
src/Mail/{EmailName}.phptemplates/emails/{template_name}.html.twigIMPORTANT : Execute ce workflow etape par etape :
Question: "Quel type d'email generer ?"
Header: "Type"
Options:
- "TemplatedEmail (Recommande)" : "Email avec template Twig — ideal pour les emails transactionnels"
- "Notification" : "Notification multicanal (email + browser + chat) via Notifier"
Question: "Quel est le nom de l'email ? (ex: WelcomeEmail, OrderConfirmation, PasswordReset)"
Header: "Email"
Question: "Quelles variables passer au template ? Format: user:User,order:Order,resetUrl:string (laisser vide si aucune)"
Header: "Variables"
Question: "Quelles options activer ?"
Header: "Options"
Options:
- "Attachments" : "Support des pieces jointes"
- "Priority" : "Definir la priorite de l'email (high, normal, low)"
- "Inline CSS" : "Utiliser Twig Inky pour le responsive email"
composer.json avec Readautoload.psr-4App par defautTemplatedEmail :
<?php
declare(strict_types=1);
namespace {namespace}\Mail;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Address;
final class {EmailName}
{
public function __construct(
private readonly MailerInterface $mailer,
private readonly string $senderEmail,
private readonly string $senderName,
) {
}
public function send(User $user): void
{
$email = (new TemplatedEmail())
->from(new Address($this->senderEmail, $this->senderName))
->to(new Address($user->getEmail(), $user->getFullName()))
->subject('Bienvenue !')
->htmlTemplate('emails/{template_name}.html.twig')
->context([
'user' => $user,
])
;
$this->mailer->send($email);
}
}
Notification :
<?php
declare(strict_types=1);
namespace {namespace}\Notification;
use Symfony\Component\Notifier\Message\EmailMessage;
use Symfony\Component\Notifier\Notification\EmailNotificationInterface;
use Symfony\Component\Notifier\Notification\Notification;
use Symfony\Component\Notifier\Recipient\EmailRecipientInterface;
final class {EmailName} extends Notification implements EmailNotificationInterface
{
public function __construct(
private readonly User $user,
) {
parent::__construct('Subject de la notification');
}
public function asEmailMessage(EmailRecipientInterface $recipient, ?string $transport = null): ?EmailMessage
{
$email = EmailMessage::fromNotification($this, $recipient);
// Personnalisation si necessaire
return $email;
}
public function getChannels(EmailRecipientInterface $recipient): array
{
return ['email'];
}
}
Regles de generation :
finalMailerInterface pour l'envoiTemplatedEmail pour les emails avec template TwigAddress avec nom pour l'expediteur et le destinataire#[Autowire] ou bindtemplates/emails/->attachFromPath() ou ->attach()->priority(Email::PRIORITY_HIGH)templates/emails/{template_name}.html.twig avec Write{% extends '@email/default/notification/body.html.twig' %}
{% block content %}
<h1>Bienvenue {{ user.fullName }}</h1>
<p>
Votre compte a ete cree avec succes.
</p>
{% block action %}
<a href="{{ url('app_dashboard') }}" class="btn btn-primary">
Acceder a mon compte
</a>
{% endblock %}
{% endblock %}
Si pas d'extension du layout par defaut :
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<h1>Bienvenue {{ user.fullName }}</h1>
<p>
Votre compte a ete cree avec succes.
</p>
<a href="{{ url('app_dashboard') }}">Acceder a mon compte</a>
</body>
</html>
Affiche :
Email {EmailName} genere avec succes
Fichiers crees :
- src/Mail/{EmailName}.php
- templates/emails/{template_name}.html.twig
Utilisation :
$this->{emailName}->send($user);
Configuration (services.yaml) :
services:
{namespace}\Mail\{EmailName}:
arguments:
$senderEmail: '%env(MAILER_FROM_EMAIL)%'
$senderName: '%env(MAILER_FROM_NAME)%'
Prochaines etapes :
- Configurer le DSN du mailer dans .env : MAILER_DSN=smtp://...
- Personnaliser le template Twig
- Ajouter les variables d'environnement MAILER_FROM_EMAIL et MAILER_FROM_NAME
final dediee a un type d'emailTemplatedEmail avec template TwigAddress pour expediteur et destinataireNotification, implements EmailNotificationInterfaceTemplatedEmail a Email pour la separation contenu/presentationAddress avec le nom pour un meilleur affichagesymfony/twig-extra-bundle avec Inky