Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
Send mail in custom hook in directus 9 not working

Here is my code for a custom hook that i use to expand directus 9.

I want to send a mail when a specific field in the events table gets updated. For now iÄm only checking if the events table gets updated. Then through the MailService i want to send an email. the code executes and logs 'mail sent' but there is no mail going out.

I have a custom template also which follows after the code. And indeed the template file is picked up and recognized. I check by removing it, then i get an error that the template is missing.

/extensions/hooks/event-time-update/index.js

module.exports = function registerHook({ action }, { services, exceptions }) {
  const { MailService } = services;
  const { ServiceUnavailableException, ForbiddenException } = exceptions;

  // Send mail to admin when event time is updated
  action('items.update', async ({ collection }, { schema }) => {
    if (collection !== 'events') return;

    const mailService = new MailService({ schema });

    try {
      await mailService.send({
        to: 'abc@gmail.com',
        subject: 'Event time updated',
        text: 'Event time updated',
        template: {
          name: 'event-time-update',
          data: {
            collection: collection,
          },
        },
      });
      console.log('mail sent');
    } catch (error) {
      console.error(error);
      throw new ServiceUnavailableException(error);
    }

    return;
  });
};

/extensions/templates/event-time-update.liquid

    {% layout "base" %}
{% block content %}

<p>
    Die Veranstalungszeit der Veranstaltung <i>{{ projectName }}</i> wurde geändert.
</p>

<p style="text-align: center; padding: 20px 0;">
    <a href="{{ url }}">
        <b>{{ projectName }} ansehen</b>
    </a>
</p>

<p>
    Thank you,<br>
    The {{ projectName }} Team
</p>

{% endblock %}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Okay nevermind, it's working. Forgot to replace abc@gmail.com 😫

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda