Skip to content

Add resend mock for development #22

@jerebenitez

Description

@jerebenitez

I don't know if this is a good practice or not, which is why I created an issue instead of just doing a pull request, but I like having a mock service for emails while on development that just prints the resulting e-mail to console.

Right now, my src/lib/send-email.tsx looks like this:

import { Resend } from "resend";
import { render } from '@react-email/render';

import { env } from "@/env";
import { ReactNode } from "react";

const resend = new Resend(env.EMAIL_SERVER_PASSWORD);

export async function sendEmail(
  email: string,
  subject: string,
  body: ReactNode
) {

  if (env.NODE_ENV === "production") {
    const { error } = await resend.emails.send({
      from: env.EMAIL_FROM,
      to: email,
      subject,
      react: <>{body}</>,
    });

    if (error) {
      throw error;
    }
  } else {
    const Body = () => <>{body}</>

    console.log(`from: ${env.EMAIL_FROM}`)
    console.log(`to: ${email}`)
    console.log(`subject: ${subject}`)
    console.log(`body: ${render(<Body />, { plainText: true })}`)
  }

}

using render from react-email. I can make the pull request if needed, but I wanted to know your opinion on this before.

Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions