1. Before you start the tutorial
Note: Ensure that you've set up the database before proceeding with this step. If you haven't done so yet, please refer to our database-tutorial.
2. Resend
You have to set up your own resend-account account. If you have have any issue with that, please check the official-resend-docs of resend.
Note: Ensure that you set your RESEND_SECRET_KEY in your .env.local file.
3. Collecting emails with newsletter
To send emails to your users, you must collect their email addresses. You can do it with our premade mailing list component. Just add it to your page. Your customers then just need to provide their email in the form.
4. Sending emails
To send emails to your users, you must collect their email addresses. You can do it with our premade mailing list component. Just add it to your page. Your customers then just need to provide their email in the form.
You can just send emails to your users from the following endpoint:
POST REQUEST: http://localhost:3000/api/email/
Calling this api endpoint will fetch all the active subscribers from the database. And send them a test email!
Here is an example code how you can access the endpoint from your components:

example email broadcast

1
2const Page = () => {
3  async function sendEmails() {
4    const subject = "Testing email";
5    fetch('/api/email/', {
6      method: "POST",
7      body: JSON.stringify({ subject }),
8    })
9      .then((res) => res.json())
10      .then((data) => {        
11      });
12  }
13  return(
14    <>
15      <button onClick={sendEmails}>Send emails to your customers</button>
16    </>
17  );
18}
You can just create your own email template with html, and include it in your api like this:

code snippet from /app/api/email/route.ts

1
2const { data, error } = await resend.emails.send({
3  from: "info@yourdomain.com",
4  to: emails,
5  subject: request.subject,
6  html: "<strong>This is an example email sent from Resend!</strong>",
7});
8
Note: You must set your own domain email address here. If you need help, please check the following resend-domain-docs.