Oro\Bundle\EmailBundle\Entity\EmailAddress class. Every bundle can provide its own email templates and notification rules.
Email templates
Create reusable Twig-based email templates by providing a data fixture that extendsAbstractEmailFixture:
Template file format
The email format is determined by the template file extension:| Extension | Email format |
|---|---|
.html.twig, .html | HTML |
.txt.twig, .txt | Plaintext |
Template metadata parameters
Each template file must include metadata as Twig comment parameters:| Parameter | Mandatory | Description |
|---|---|---|
@entityName | Yes | Fully-qualified class name of the email owner entity. |
@subject | Yes | The email subject. |
@name | No | Template name shown in the UI (defaults to filename without extension). |
@isSystem | No | Set to 1 to mark as a system template. |
@isEditable | No | Set to 1 (with @isSystem=1) to allow editing via the UI. |
Creating and sending emails
- Manual creation
- EmailModelBuilder
Create an
Email model instance and populate it via setters:Sending the email
Use theoro_email.sender.email_model_sender service to send and persist the email:
send() is called, the mailer sender:
Creates a Symfony Email instance
Populates
\Symfony\Component\Mime\Email with data from the Email model.Determines the email origin
If no
EmailOrigin is provided, one is created based on the sender address and selected organization.Sends the email
Uses the application’s mailer configuration, or the user’s custom SMTP server if configured.
Email notifications
To receive emails when Doctrine entities are created, updated, or removed, create anEmailNotification data fixture:
Email address owners
Each email address belongs to exactly one entity (e.g.,User, Contact). To make your own entity own an email address:
Implement the email entity
Create an entity implementing
Oro\Bundle\EmailBundle\Entity\EmailInterface:getEmailField()— column that holds the email addressgetId()— unique identifiergetEmail()— the actual email addressgetEmailOwner()— the owning entity
Implement the owner entity
Make the owner entity implement
Oro\Bundle\EmailBundle\Entity\EmailOwnerInterface:getClass()— fully qualified class namegetEmailFields()— list of email address propertiesgetId()— unique identifiergetFirstName()/getLastName()— used when building recipient names
Create an EmailOwnerProvider
Implement
Oro\Bundle\EmailBundle\Entity\Provider\EmailOwnerProviderInterface and register it as a service tagged oro_email.owner.provider: