How to implement my own plugin able to merge tokens on e-mails

Hello there!

My name is Matias and I’m trying to implement Mautic in our company.

I already have a working environment, but I came across a specific requirement: I need to use a mailer service that provides a rudimentary JSON API and does not support token replacement.

Anyway, I set out to try and implement a plugin to support this service.

I am already sending emails, but without being able to merge the tokens.

From my understanding of the problem, this work is done by default by the mailer service.

Is there any way for this to be processed by my plugin? From the little I’ve studied, I imagine implementing a service derived from EmailSubscriber. Do you have any reference code so I can investigate?

I know this is a lot of questions for a first post, but I appreciate any document you can indicate.

Thank you!

Matias.

Hi Matias, my understand is that the mautic tokens (https://docs.mautic.org/en/setup/variables) are processed by mautic before sending it to the mailer/smtp service.

Hi Leo.

Thanks for the answer.

This was my understanding too until I saw my messages being delivered without the tokens being replaced.

The tracking pixel is also not embedded as it is also a token.

If Mautic must do this, then I need to take some action before sending the payload expected by the email service API. What would it be?

Thank you for your attention.

Matias.

a while ago I was using elasticmail which has its own tokens that you can use, and I remember having to handle both steps of token replacement, from mautic and from elastic mail. so I guess your issue is in the mautic configuration/ setup because handling the tokens should be a standard feature.

perhaps posting this issue on configuration and support topics (Support - Mautic Community Forums) would be better and people might be able to figure out why your tokens are not being replaced.

Leo, thank you for your time and patience. I will try your suggestion.

@edneymatias, To have the visibility of custom tokens in email please make sure to subscribe the following events,

  1. \Mautic\EmailBundle\EmailEvents::EMAIL_ON_BUILD: List token for builders
  2. \Mautic\EmailBundle\EmailEvents::EMAIL_ON_SEND: Should the replacements when sending.
  3. \Mautic\EmailBundle\EmailEvents::EMAIL_ON_DISPLAY: Should replacements when previewing or display.

The CustomObject plugin have these implemented, please check https://github.com/acquia/mc-cs-plugin-custom-objects/blob/2865eb90a3c333ee9e5895698e15e83c283fa689/EventListener/TokenSubscriber.php