Client installieren

npm-Client installieren und E-Mails mit einem API Key senden.

1. Paket installieren

npm install tuix-email-service-client

2. Client konfigurieren

Konfiguriere den Client mit der Basis-URL und deinem API Key. Der API Key wird im x-api-key-Header gesendet.

Ein privater API Key gehört nur auf den Server. Nur ein als öffentlich erstellter Key darf im Frontend verwendet werden. Siehe API Keys.

import { ClientApi, Configuration } from 'tuix-email-service-client'
 
export const emailClient = new ClientApi(
    new Configuration({
        basePath: process.env.API_BASE_URL,
        headers: {
            'x-api-key': process.env.TUIX_EMAIL_API_KEY,
        },
    }),
)

3. E-Mail senden

await emailClient.apiSendEmail({
    applicationId: 'YOUR_APPLICATION_ID',
    to: '[email protected]',
    templateUUID: 'YOUR_TEMPLATE_UUID',
    data: JSON.stringify({ name: 'Jane' }),
})

applicationId, templateUUID und to sind erforderlich. data enthält die Variablen der Vorlage als JSON-String. Optional: body (Inline-Inhalt) und file (Anhang). Siehe E-Mail-Parameter.

Auf dieser Seite