Development Guides



The Mail API provides a straightforward way to send emails to users. To send emails, we use the sendMail() method, which is available through the generated SDK. This method is housed in the ROQ platform and can be accessed using the roqServerClient object.

Code examples

Let's take an example in the Next.js project with the generated SDK installed in the default src/lib/roq folder. We can send an email to a user by using the following code:

import { roqServerClient } from '@/lib/roq/roq-server-client';
const sendMyMail = async() => {
    await roqServerClient.roqPlatform.asSuperAdmin().sendMail({
        mail: {
            key: 'onboarding',
            locale: 'en-US',
            emails: [''],
            data: [{ key: 'name', value: 'Francis84 Columbus' }] }

In the framework such as Next.js. We only can use the sendMail() on the server side. Any method from roqServerClient is always executed on the server side.

To be able to send an email to a user, we also need to create a mail template in the ROQ Console (opens in a new tab). The mail template is a simple HTML template with some variables. The variables are replaced with the data that we send in the sendMail() method. Please check the mail template section for more information about the mail template.

Frameworks integration

The Mails API can be used in any ROQ's supported JavaScript frameworks such as Next.js, Nuxt.js, SvelteKit, Express.js, and RedwoodJS. Other than specific ROQ framework packages such as @roq/nextjs, there is no need to install any additional packages to use the Mail API. When we generate the SDK using @roq/cli, the generated SDK will provide the sendMail() method.