discard plain text renderer

This commit is contained in:
m5r 2021-10-30 13:37:16 +02:00
parent 8e860a1ea3
commit 55f9083e7c
3 changed files with 9 additions and 19 deletions

View File

@ -11,7 +11,7 @@ const credentials = new Credentials({
const ses = new SES({ region: serverRuntimeConfig.awsSes.awsRegion, credentials });
type SendEmailParams = {
text: string;
text?: string;
html: string;
subject: string;
recipients: string[];
@ -22,10 +22,12 @@ export async function sendEmail({ text, html, subject, recipients }: SendEmailPa
Destination: { ToAddresses: recipients },
Message: {
Body: {
Text: {
Text: text
? {
Charset: "UTF-8",
Data: text,
},
}
: undefined,
Html: {
Charset: "UTF-8",
Data: html,

View File

@ -1,7 +1,7 @@
import previewEmail from "preview-email";
import { sendEmail } from "integrations/aws-ses";
import { render, plaintext } from "./renderer";
import { render } from "./renderer";
type ResetPasswordMailer = {
to: string;
@ -13,16 +13,12 @@ export async function forgotPasswordMailer({ to, token, userName }: ResetPasswor
// In production, set APP_ORIGIN to your production server origin
const origin = process.env.APP_ORIGIN || process.env.BLITZ_DEV_SERVER_ORIGIN;
const resetUrl = `${origin}/reset-password?token=${token}`;
const [html, text] = await Promise.all([
render("forgot-password", { action_url: resetUrl, name: userName }),
plaintext("forgot-password", { action_url: resetUrl, name: userName }),
]);
const html = await render("forgot-password", { action_url: resetUrl, name: userName });
const msg = {
from: "mokhtar@shellphone.app",
to,
subject: "Reset your password",
html,
text,
};
return {
@ -32,7 +28,6 @@ export async function forgotPasswordMailer({ to, token, userName }: ResetPasswor
recipients: [msg.to],
subject: msg.subject,
html: msg.html,
text: msg.text,
});
} else {
// Preview email in the browser

View File

@ -10,13 +10,6 @@ export async function render(templateName: string, locals: Record<string, string
return html;
}
export async function plaintext(templateName: string, locals: Record<string, string> = {}) {
const { template, options } = getMaizzleParams(templateName, locals);
const { plaintext } = await Maizzle.plaintext(template, options);
return plaintext;
}
function getMaizzleParams(templateName: string, locals: Record<string, string>) {
const template = fs
.readFileSync(path.resolve(process.cwd(), "./mailers/templates", `${templateName}.html`))