Overview

You need to set up an email service to send emails to your users. Please do not spam your users with unnecessary emails to avoid being marked as spam. It's important to keep the healthy reputation of your email service provider.

How to Use

Here is an example of how to send an email:

ts

import { sendMail } from '@/lib/server/email' await sendMail({ to: { email: '[email protected]', name: 'John Doe' }, subject: 'Whoops! You forgot something in your cart 😱', body: { template: 'marketing01', params: { app: 'NextReady', name: 'John Doe', link: 'https://example.com' } } })

Parameter Options

  • to (required) object

    The recipient's email address and name.

    • email (required) string: The valid recipient's email address.

    • name string: The recipient's name.

  • subject (required) string: The email subject.

  • from string: The sender's email address (default: process.env.EMAIL_FROM).

  • body (required) object

    Build the email content with HTML string OR template. It supports the template engine format by using {{param}} (or, {{{param}}} to prevent escaping) syntax and provide the parameters in the params object.

    • html string: The email content in HTML format.

    • template string: The email template name without the .html extension. Make sure to create the template in the templates/email folder as an HTML file.

    • params object: The email template parameters.

Create Email Template

You can create a simple and beautiful email template for free with Maily. Copy and save the generated HTML code in the templates/email folder.