Email

Veloz support sending of mails using Resend due to it simplicity. If you dont have a resend account , create one here (opens in a new tab).

Resend

Setup 🛠

Head over to your resend dashboard and create a new API Key as seen in the image below.

image

Once that completed, navigate to the Domain section and add a new domain. If you dont have one, you could purchase one from Namecheap (opens in a new tab) or Godaddy (opens in a new tab).

image

⚠️

Make sure it verified before proceeding further.

Now, Copy the API Key alongside your Domain Name and head over to your project .env file and update the following variable.

.env

_10
# resend email config
_10
RESEND_API_KEY="re_xxxxxxxxxxxx"
_10
_10
# mail
_10
MAIL_FROM="Veloz <[email protected]>"

Usage 🚀

Veloz provide a reusable promise base function based on the preferred mail provider. It differ based on the language of choice.

Javascript

Next.js (app router)

Simply headover to src/app/api/config/email/resend.(ts) a function called resendSendMail() has been provided for you. It accept the following parameters.

  • to - The recipient email address or addresses.
  • subject - The subject of the mail.
  • htmlData - The html content of the mail.

The htmlData variable holds the HTML content of the email. Veloz provides a base email template located in src/email-template. Find it in the preview folder for designing your HTML mail template. Once completed, copy it and create a function in src/email-template/. For mail templates with dynamic data, create a reusable function similar to the one in src/email-template/welcome-template.(ts/js).

image

If the current approach doesn't suit your comfort level, feel free to modify this function according to your preferred approach.

Using the resendSendMail() function, you can send mail to a single or multiple recipients.

test.js

_10
import resendSendMail from "../config/email/resend";
_10
import waitlistWelcome from "@/email-template/waitlist-welcome";
_10
_10
const email = "[email protected]";
_10
const emailTemp = waitlistWelcome(email, "Veloz");
_10
await resendSendMail(email, "🥳 Waitlist", emailTemp);

waitlist-welcome.ts

_38
const waitlistWelcome = (email: string, appName = "Veloz") => {
_38
return `
_38
<!DOCTYPE html>
_38
<html lang="en">
_38
<head>
_38
<meta charset="UTF-8" />
_38
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
_38
<title>Waitlist - Welcome</title>
_38
<style>
_38
body {
_38
font-family: Arial, sans-serif;
_38
}
_38
.email-content {
_38
max-width: 600px;
_38
margin: 0 auto;
_38
}
_38
</style>
_38
</head>
_38
<body>
_38
<div class="email-content">
_38
<p style="font-size: 16px">Hi ${email},</p>
_38
_38
<p style="font-size: 16px">
_38
Thank you for joining our waitlist. We will notify you when we are ready
_38
to launch.
_38
</p>
_38
_38
<p style="font-size: 16px">Regards,</p>
_38
_38
<p style="font-size: 16px">The ${appName} Team</p>
_38
</div>
_38
</body>
_38
</html>
_38
_38
`;
_38
};
_38
_38
export default waitlistWelcome;

© Veloz 2024