https://github.com/mailslurp/examples
{
"name": "javascript-react-email",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "vitest --watch=false"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@react-email/button": "^0.0.10",
"@react-email/html": "^0.0.4",
"@react-email/render": "^0.0.7",
"@react-email/text": "^0.0.5",
"mailslurp-client": "^15.17.2",
"nodemailer": "^6.9.5",
"react-email": "^1.9.5"
},
"devDependencies": {
"vite": "^4.4.10",
"vitest": "^0.34.6"
}
}
# React Email nodemailer end-to-end test example
How to test emails created with React Email using MailSlurp disposable email addresses.
-include ../.env
.PHONY: test
node_modules:
npm install
docker:
test: node_modules
API_KEY=$(API_KEY) npm t
//<gen>react-email-template
import * as React from 'react';
import { Html } from '@react-email/html';
import { Text } from '@react-email/text';
export function Email(props) {
const { code } = props;
return (
<Html lang="en">
<Text>Your code is: {code}</Text>
</Html>
);
}
//</gen>
//<gen>react-email-send-email
import { render } from '@react-email/render';
import { Email } from './react-email';
import nodemailer from 'nodemailer';
export async function sendEmail(code, mail, server) {
const transporter = nodemailer.createTransport({
host: server.host,
port: server.port,
secure: false,
auth: {
user: server.user,
pass: server.pass,
},
});
const emailHtml = render(Email({ code }));
const options = {
from: mail.sender,
to: mail.to,
subject: mail.subject,
html: emailHtml,
};
await transporter.sendMail(options);
}
//</gen>