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

Have the text property automatically filled when the react property is used when sending emails. #369

Open
ValentinH opened this issue Jun 7, 2024 · 3 comments

Comments

@ValentinH
Copy link

Do you recommend to always send a text version of an email along with the html version? If yes, could we have the SDK automatically set the text property when we use the react one (doing a second render with the plainText: true option)?

@bukinoshita
Copy link
Member

Do you recommend to always send a text version of an email along with the html version? If yes, could we have the SDK automatically set the text property when we use the react one (doing a second render with the plainText: true option)?

Yes, having the text version of the email is usually recommended.
That's a great suggestion, ideally this should be on API side so user never needs to send the text version doesn't matter which SDK they are using. Doing on SDK side with React Email is easier though

We will explore more

@jessethomson
Copy link

It seems this still hasn't been implemented.

In the meantime, is this how you all would recommend working around this?

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

const resend = new Resend('re_123456789');

async function sendEmail() {
    const jsx = <MyTemplate />;
    const text = await render(jsx, {
        plainText: true,
    });

    await resend.emails.send({
        from: 'Acme <[email protected]',
        to: ['[email protected]'],
        subject: 'hello world',
        react: jsx,
        text,
    });
}

@sommeeeer
Copy link

sommeeeer commented Sep 13, 2024

It seems this still hasn't been implemented.

In the meantime, is this how you all would recommend working around this?

yeah this is how i am using it, but i must agree i would love it to have an option for automagically sending a text version along with a react email. for now this is what i do:

async function sendEmail({
  from,
  to,
  subject,
  component,
}: {
  from: string;
  to: string | string[];
  subject: string;
  component: JSX.Element;
}) {
  const [html, text] = await Promise.all([
    render(component),
    render(component, {
      plainText: true,
    },)
  ]);
  const { data, error } = await resend.emails.send({
    from,
    to,
    subject,
    html: html,
    text: text,
  });
  if (error) {
    throw new Error(error.message);
  }
  return data;
}

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

4 participants