mirror of
https://github.com/lukevella/rallly.git
synced 2025-07-18 00:37:27 +02:00
✨ Add plain text version for each email (#1005)
This commit is contained in:
parent
02abaf4f67
commit
8a523e442c
1 changed files with 9 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
||||||
import * as aws from "@aws-sdk/client-ses";
|
import * as aws from "@aws-sdk/client-ses";
|
||||||
import { defaultProvider } from "@aws-sdk/credential-provider-node";
|
import { defaultProvider } from "@aws-sdk/credential-provider-node";
|
||||||
import { render } from "@react-email/render";
|
import { renderAsync } from "@react-email/render";
|
||||||
import { createTransport, Transporter } from "nodemailer";
|
import { createTransport, Transporter } from "nodemailer";
|
||||||
import type Mail from "nodemailer/lib/mailer";
|
import type Mail from "nodemailer/lib/mailer";
|
||||||
import previewEmail from "preview-email";
|
import previewEmail from "preview-email";
|
||||||
|
@ -79,21 +79,26 @@ export class EmailClient {
|
||||||
options: SendEmailOptions<T>,
|
options: SendEmailOptions<T>,
|
||||||
) {
|
) {
|
||||||
const Template = templates[templateName] as TemplateComponent<T>;
|
const Template = templates[templateName] as TemplateComponent<T>;
|
||||||
const html = render(
|
const component = (
|
||||||
<Template
|
<Template
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
{...(options.props as any)}
|
{...(options.props as any)}
|
||||||
ctx={this.config.context}
|
ctx={this.config.context}
|
||||||
/>,
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const [html, text] = await Promise.all([
|
||||||
|
renderAsync(component),
|
||||||
|
renderAsync(component, { plainText: true }),
|
||||||
|
]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.sendEmail({
|
await this.sendEmail({
|
||||||
from: this.config.mail.from,
|
from: this.config.mail.from,
|
||||||
to: options.to,
|
to: options.to,
|
||||||
subject: options.subject,
|
subject: options.subject,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
html,
|
html,
|
||||||
|
text,
|
||||||
attachments: options.attachments,
|
attachments: options.attachments,
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue