@effit/email
v0.1.0-alpha.7
Published
React Email + nodemailer integration for the Effit framework.
Readme
@effit/email
React Email + nodemailer integration for the Effit framework.
Email.make(name, dataSchema, emailerEffect) builds a type-safe email factory that renders React Email components and produces nodemailer-ready SendMailOptions.
Installation
pnpm add @effit/email effect react-email react nodemailerDefining an email
import { Effect, Schema } from 'effect';
import { Email } from '@effit/email/Email.js';
import TodoCreatedTemplate from './TodoCreatedTemplate.js';
const TodoCreatedEmailData = Schema.Struct({
todoId: Schema.String,
to: Schema.NonEmptyString,
title: Schema.NonEmptyString,
});
export const TodoCreatedEmail = Email.make(
'TodoCreatedEmail',
TodoCreatedEmailData,
Effect.gen(function* () {
return (data, { render }) =>
Effect.gen(function* () {
const html = yield* render(<TodoCreatedTemplate title={data.title} />);
return {
to: data.to,
subject: 'New todo created',
html,
};
});
}),
);dataSchemais wrapped in aSchema.TaggedStruct(name, ...)so tagged-union email dispatch works without the caller passing_tag.emailerEffectruns once per process (good place to read transport config); its returned function runs per email and must resolve to a nodemailerSendMailOptions.- The
{ render }helper is injected by the caller (typically a BullMQ email job) so@effit/emailitself stays decoupled fromreact-email's runtime.
Sending
Emails are usually enqueued through @effit/workers' QueuingService and delivered by a dedicated email job that calls render from react-email and hands the result to nodemailer.
License
MIT © Talysson de Oliveira Cassiano
