Sending Emails

Most emails should be sent by the order processing systems and not by Frontastic itself. But, Frontastic does send all account related emails, like registration confirmations and forgot password emails. The easiest way to do this is to configure an SMTP server, but you can also write a custom mailer which talks to a web service for sending these emails – this is especially useful to maintain email templates outside of Frontastic.

Configure Outgoing Mail Server

The easiest way to setup mail handing is by configuring an SMTP server which has to be reachable from the production servers with their changing IPs. For this use the committed environment file inside your project directory, from example, <customer>_<project>/environment and add the following settings:

Frontastic doesn't provide any default email templates at the moment. You can create you own templates in the directory <customer>_<project>/templates/Emails/ (mind the capital E) which can then be used for the email templates listed below. We send emails as text and HTML by default, so there are two templates for every email Frontastic sends:

  • Registration: register.html.twig and register.txt.twig
  • Reset Password: reset.html.twig and reset.txt.twig
  • On top of this, it makes sense to create an email layout template for HTML emails: layout.html.twig

An example template for the register.txt.twig could look like:

Hello {{user.salutation}} {{user.lastName}},

To complete the registration please click on the following link. This link
will be valid until {{user.tokenValidUntil|date('d.m.Y H:i')}}.

{{absolute_url(path('Frontastic.Frontend.Master.Account.confirm', {confirmationToken: token}))}}

Best regards,

The information provided for an email template to reset a password will look very similar:

Hello {{user.salutation}} {{user.lastName}},

we received a request for your account to reset the password. To
process with a new password, please click the link below. If you did
not request this password reset, you can simply ignore this mail. Your
link is valid until {{user.tokenValidUntil|date('Y-m-d H:i')}}.

{{absolute_url(path('Frontastic.Frontend.Master.Account.forgotPassword', {confirmationToken: token}))}}


Custom Mailer

Please note, this method is Experimental so use at your own risk.

If you can't send out emails using a common SMTP server, you can overwrite the mailer class and use any service to trigger sending these emails. For this, you can use the default Symfony mechanism in the Dependency Injection Container to overwrite the default mailer. To do this, just add the below lines to a service.xml in one of your Project bundles (if there isn't a bundle yet, you can create one using bin/console frontastic:create:bundle MyDecorators, for example):

    class="Acme\MyDecoratorsBundle\Domain\MyMailer" />

The Customer Mailer class must extend and overwrite the Frontastic\\Common\\CoreBundle\\Domain\\Mailer class, which only has one single method:


namespace Acme\MyDecoratorsBundle\Domain;

use Frontastic\Common\CoreBundle\Domain\Mailer;

class MyMailer extends Mailer
    public function sendToUser($user, string $type, string $subject, array $parameters = array())
        // @TODO: Send mail

The type parameter should be register or reset as used in the template names before. The token will be part of the $parameters array.

‹ Back to Article List

Next Article ›

Custom APIs

Still need help? Contact Us Contact Us