- Manage all outgoing mails in one central place by configuring them in one single yaml configuration file.
- Disable or reroute all mails for debugging with one switch. Therefore you can already define the correct live email addresses during development and have not to worry about forgetting to switch them back when going live.
- Output the mail contents to accessible html files for quick debugging without having to spam your inbox.
Install the extension using Composer: composer require codeminds/mailmanager
.
- Create a yaml file for your mail configuration (for example inside your site package extension in Configuration/Yaml/Mails.yaml)
- Define the location of your yaml file via TypoScript:
plugin.tx_mailmanager.settings.configurationFilePath = EXT:your_site_package/Configuration/Yaml/Mails.yaml
- Set up your first mail configuration in your yaml file (
EXT:your_site_package/Configuration/Yaml/Mails.yaml
):
configurations:
-
identifier: 'MyIdentifier'
isActive: true
senderEmailAddress: '[email protected]'
senderName: 'My sender'
recipients:
-
emailAddress: '[email protected]'
name: 'My recipient'
subject: 'My subject'
templatePathAndFileName: 'EXT:your_site_package/Resources/Private/Templates/Mails/YourIdentifier.html'
partialRootPaths: []
layoutRootPaths: []
debug:
disableDelivery: false
enableRerouting: false
reroutingEmailAddress: '[email protected]'
reroutingName: 'Debug'
enableDebugOutputToFiles: false
- Define your template (
EXT:your_site_package/Resources/Private/Templates/Mails/YourIdentifier.html
):
<p>Dear customer,</p>
<p>this is a hello {variable} example mail</p>
<p>Cheers</p>
- Use the provided MailService to send your mails:
use TYPO3\CMS\Extbase\Annotation\Inject;
/**
* @Inject
* @var Codeminds\MailManager\Service\MailService
*/
protected $mailService = null;
.
.
.
$variables = array('variable' => 'world');
$this->mailService->sendMail('MyIdentifier', $variables);
You can use variables in your yaml configuration to e.g. set the recipient dynamically. Refer to the variable by using curly brackets: {variableName}
. It is also possible to refer to nested variables: {variable.nested.variableName}
.
Example:
configurations:
-
identifier: 'MyIdentifier'
isActive: true
senderEmailAddress: '[email protected]'
senderName: 'My sender'
recipients:
-
emailAddress: '{variableName}'
.
.
.
- Include the static TypoScript of the extension.
- You can now add the two new finishers in the form module: Email to submitter (via MailManager) and Email to you (via MailManager)
- In the finisher you have to define the identifier of your corresponding mail configuration
- Optionaly you can set the receiver or sender to a dynamically set value coming from the form (the mail configuration has to be defined accordingly by setting
{emailAddress}
or{name}
) - Define the templates and partials of the form extension (or use your own). In your yaml mail configuration:
templatePathAndFileName: 'EXT:form/Resources/Private/Frontend/Templates/Finishers/Email/Html.html'
partialRootPaths: ['EXT:form/Resources/Private/Frontend/Partials']
Use the self explanatory options under debug
in your yaml file. If enableDebugOutputToFiles
is on, the files will be put to /typo3temp/mails/MyIdentifier.html for quick access via your browser.
You can also configure cc, bcc, reply-to addresses and attachments. See this configuration with all possible options used:
configurations:
-
identifier: 'MyIdentifier'
isActive: true
senderEmailAddress: '[email protected]'
senderName: 'My sender'
recipients:
-
emailAddress: '[email protected]'
name: 'My recipient'
cc:
-
emailAddress: '[email protected]'
name: 'My cc recipient'
bcc:
-
emailAddress: '[email protected]'
name: 'My bcc recipient'
replyTo:
-
emailAddress: '[email protected]'
name: 'My replyto name'
subject: 'My subject'
attachments: ['EXT:your_site_package/Resources/Private/Pds/attachment.pdf']
templatePathAndFileName: 'EXT:your_site_package/Resources/Private/Templates/Mails/YourIdentifier.html'
partialRootPaths: []
layoutRootPaths: []
debug:
disableDelivery: false
enableRerouting: false
reroutingEmailAddress: '[email protected]'
reroutingName: 'Debug'
enableDebugOutputToFiles: false
Attach files programmatically:
$pathAttachments[] = 'EXT:your_site_package/Resources/Private/Pds/attachment.pdf';
$file = $myFileReference->getOriginalResource();
$swiftAttachments[] = Swift_Attachment::newInstance($file->getContents(), $file->getName(), $file->getMimeType());
$this->mailService->sendMail('MyIdentifier', $variables, $pathAttachments, $swiftAttachments);