UNPKG

@lucidcms/plugin-nodemailer

Version:

The official Nodemailer plugin for Lucid

95 lines (89 loc) 2.31 kB
// src/translations/en-gb.json var en_gb_default = { email_successfully_sent: "The email was successfully sent.", email_transporter_not_ready: "The email transporter is not ready." }; // src/translations/index.ts var selectedLang = en_gb_default; var T = (key, data) => { const translation = selectedLang[key]; if (!translation) { return key; } if (!data) { return translation; } return translation.replace( /\{\{(\w+)\}\}/g, (_, p1) => data[p1] ); }; var translations_default = T; // src/utils/verify-transporter.ts import { logger } from "@lucidcms/core"; // src/constants.ts var PLUGIN_KEY = "plugin-nodemailer"; var LUCID_VERSION = "0.x.x"; // src/utils/verify-transporter.ts var verifyTransporter = async (transporter) => { try { await transporter.verify(); } catch (error) { if (error instanceof Error) { logger("warn", { message: error.message, scope: PLUGIN_KEY }); return; } logger("warn", { message: translations_default("email_transporter_not_ready"), scope: PLUGIN_KEY }); } }; var verify_transporter_default = verifyTransporter; // src/plugin.ts var plugin = async (config, pluginOptions) => { await verify_transporter_default(pluginOptions.transporter); config.email = { from: pluginOptions.from, strategy: async (email, meta) => { try { await pluginOptions.transporter.sendMail({ from: `${email.from.name} <${email.from.email}>`, to: email.to, subject: email.subject, cc: email.cc, bcc: email.bcc, replyTo: email.replyTo, text: email.text, html: email.html }); return { success: true, message: translations_default("email_successfully_sent") }; } catch (error) { const err = error; return { success: false, message: err.message }; } } }; return { key: PLUGIN_KEY, lucid: LUCID_VERSION, config }; }; var plugin_default = plugin; // src/index.ts var lucidNodemailerPlugin = (pluginOptions) => (config) => plugin_default(config, pluginOptions); var src_default = lucidNodemailerPlugin; export { src_default as default }; //# sourceMappingURL=index.js.map