How to send emails
There are a few steps to send emails using ROQ BaaS SDK: You need to configure an email provider, you need to create an email template, and you can send emails via API.
Configure email provider
Make sure that an email provider is connected and activated. You will find a list of all integrations in the ROQ Console (opens in a new tab). To set up the email integration, please read this documentation section.
Create an email template
Before sending emails, make sure to create email templates on the ROQ Console. To create an email template, read this documentation.
Send emails via API
Emails are sent using the sendMail API. You need to use the same key which you set to the email type. For instance, to send a new product email with the unique key product-name
and data variables: recipients_name
and product_name
, you can send the email using the sendMail()
API in the generated SDK.
In a framework like Next.js, the sendMail
API can be called in the server-side code. For example, in Next.js 14 and later, you can call the API by using Server Actions (opens in a new tab) features.
"use server"
import { roqServerClient } from "@/lib/roq/roq-server-client";
export default async function Actions() {
const sendEmailConfirmation = await roqServerClient.roqPlatform.asSuperAdmin().sendMail({
mail: {
emails: ["francis.84p@gmail.com"],
key: "product-name",
data: [
{ key: 'recipients_name', value: 'Francis Bacon' },
{ key: 'product_name', value: 'Bacon' }],
locale: "de-DE"
}
})
}
With the use server
directive, you can call the API directly in the Next.js Client Component. For example:
import sendMailAction from "./actions.ts"
export default function SendEmail() {
const sendEmail = async () => {
await sendMailAction()
}
return (
<button onClick={sendEmail}>Send Email</button>
)
}