Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resend mock for development #22

Open
jerebenitez opened this issue Aug 14, 2024 · 1 comment
Open

Add resend mock for development #22

jerebenitez opened this issue Aug 14, 2024 · 1 comment

Comments

@jerebenitez
Copy link
Contributor

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!

@webdevcody
Copy link
Owner

that's a good idea, I'm open to a pull request as long as it's a documented env variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants