Api: Emit filter for email.send (#23024)

Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
This commit is contained in:
José Varela
2024-07-16 15:02:12 +01:00
committed by GitHub
parent 448a7a2cc3
commit c816c50e75
4 changed files with 20 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
---
"@directus/api": minor
"@directus/app": patch
---
Introduced the `email.send` filter event, allowing to modify email options via Flows or Custom Extensions

View File

@@ -12,6 +12,7 @@ import { useLogger } from '../../logger/index.js';
import getMailer from '../../mailer.js';
import type { AbstractServiceOptions } from '../../types/index.js';
import { Url } from '../../utils/url.js';
import emitter from '../../emitter.js';
const env = useEnv();
const logger = useLogger();
@@ -52,8 +53,17 @@ export class MailService {
}
}
async send<T>(options: EmailOptions): Promise<T> {
const { template, ...emailOptions } = options;
async send<T>(options: EmailOptions): Promise<T | null> {
const payload = await emitter.emitFilter(`email.send`, options, {
database: getDatabase(),
schema: null,
accountability: null,
});
if (!payload) return null;
const { template, ...emailOptions } = payload;
let { html } = options;
const defaultTemplateData = await this.getDefaultTemplateData();

View File

@@ -134,6 +134,7 @@ export function getTriggers() {
'auth.create',
'auth.update',
'authenticate',
'email.send',
],
font: 'monospace',
},

View File

@@ -205,6 +205,7 @@ export default ({ embed }, { env }) => {
| `auth.create`<sup>[1]</sup> | The created user | `identifier`, `provider`, `providerPayload` |
| `auth.update`<sup>[2]</sup> | The updated auth token<sup>[3]</sup> | `identifier`, `provider`, `providerPayload` |
| `authenticate` | The empty accountability object | `req` |
| `email.send` | The email payload | -- |
| `(<collection>.)items.query` | The items query | `collection` |
| `(<collection>.)items.read` | The read item | `query`, `collection` |
| `(<collection>.)items.create` | The new item | `collection` |