discard plain text renderer
This commit is contained in:
parent
8e860a1ea3
commit
55f9083e7c
@ -11,7 +11,7 @@ const credentials = new Credentials({
|
|||||||
const ses = new SES({ region: serverRuntimeConfig.awsSes.awsRegion, credentials });
|
const ses = new SES({ region: serverRuntimeConfig.awsSes.awsRegion, credentials });
|
||||||
|
|
||||||
type SendEmailParams = {
|
type SendEmailParams = {
|
||||||
text: string;
|
text?: string;
|
||||||
html: string;
|
html: string;
|
||||||
subject: string;
|
subject: string;
|
||||||
recipients: string[];
|
recipients: string[];
|
||||||
@ -22,10 +22,12 @@ export async function sendEmail({ text, html, subject, recipients }: SendEmailPa
|
|||||||
Destination: { ToAddresses: recipients },
|
Destination: { ToAddresses: recipients },
|
||||||
Message: {
|
Message: {
|
||||||
Body: {
|
Body: {
|
||||||
Text: {
|
Text: text
|
||||||
Charset: "UTF-8",
|
? {
|
||||||
Data: text,
|
Charset: "UTF-8",
|
||||||
},
|
Data: text,
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
Html: {
|
Html: {
|
||||||
Charset: "UTF-8",
|
Charset: "UTF-8",
|
||||||
Data: html,
|
Data: html,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import previewEmail from "preview-email";
|
import previewEmail from "preview-email";
|
||||||
|
|
||||||
import { sendEmail } from "integrations/aws-ses";
|
import { sendEmail } from "integrations/aws-ses";
|
||||||
import { render, plaintext } from "./renderer";
|
import { render } from "./renderer";
|
||||||
|
|
||||||
type ResetPasswordMailer = {
|
type ResetPasswordMailer = {
|
||||||
to: string;
|
to: string;
|
||||||
@ -13,16 +13,12 @@ export async function forgotPasswordMailer({ to, token, userName }: ResetPasswor
|
|||||||
// In production, set APP_ORIGIN to your production server origin
|
// In production, set APP_ORIGIN to your production server origin
|
||||||
const origin = process.env.APP_ORIGIN || process.env.BLITZ_DEV_SERVER_ORIGIN;
|
const origin = process.env.APP_ORIGIN || process.env.BLITZ_DEV_SERVER_ORIGIN;
|
||||||
const resetUrl = `${origin}/reset-password?token=${token}`;
|
const resetUrl = `${origin}/reset-password?token=${token}`;
|
||||||
const [html, text] = await Promise.all([
|
const html = await render("forgot-password", { action_url: resetUrl, name: userName });
|
||||||
render("forgot-password", { action_url: resetUrl, name: userName }),
|
|
||||||
plaintext("forgot-password", { action_url: resetUrl, name: userName }),
|
|
||||||
]);
|
|
||||||
const msg = {
|
const msg = {
|
||||||
from: "mokhtar@shellphone.app",
|
from: "mokhtar@shellphone.app",
|
||||||
to,
|
to,
|
||||||
subject: "Reset your password",
|
subject: "Reset your password",
|
||||||
html,
|
html,
|
||||||
text,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -32,7 +28,6 @@ export async function forgotPasswordMailer({ to, token, userName }: ResetPasswor
|
|||||||
recipients: [msg.to],
|
recipients: [msg.to],
|
||||||
subject: msg.subject,
|
subject: msg.subject,
|
||||||
html: msg.html,
|
html: msg.html,
|
||||||
text: msg.text,
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Preview email in the browser
|
// Preview email in the browser
|
||||||
|
@ -10,13 +10,6 @@ export async function render(templateName: string, locals: Record<string, string
|
|||||||
return html;
|
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>) {
|
function getMaizzleParams(templateName: string, locals: Record<string, string>) {
|
||||||
const template = fs
|
const template = fs
|
||||||
.readFileSync(path.resolve(process.cwd(), "./mailers/templates", `${templateName}.html`))
|
.readFileSync(path.resolve(process.cwd(), "./mailers/templates", `${templateName}.html`))
|
||||||
|
Loading…
Reference in New Issue
Block a user