Install the client

Install the npm client and send emails with an API key.

1. Install the package

npm install tuix-email-service-client

2. Configure the client

Configure the client with the base URL and your API key. The API key is sent in the x-api-key header.

A private API key belongs on the server only. Only a key created as public may be used in the frontend. See 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. Send an email

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

applicationId, templateUUID and to are required. data holds the template variables as a JSON string. Optional: body (inline content) and file (attachment). See Email parameters.

On this page