UNPKG

langcode

Version:

A Plugin-Based Framework for Managing and Using LangChain

76 lines (75 loc) 2.38 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const nodemailer_1 = __importDefault(require("nodemailer")); const types_1 = require("../../types"); class MailerPlugin { constructor() { this.name = "mailer"; this.description = "SMTP email sender using nodemailer."; this.type = types_1.PluginType.LangCodeTool; this.RunConfigExample = { to: "", subject: "", text: "", html: "", attachments: [{ filename: "", path: "" }] }; this.InitConfigExample = { host: "mail.domain.com", port: 587, secure: false, auth: { user: "your@mail.com", pass: "password....", }, }; this.transporter = null; this.fromEmail = null; } expose() { return { name: this.name, description: this.description, type: this.type, InitConfigExample: this.InitConfigExample, RunConfigExample: this.RunConfigExample, transporter: this.transporter, fromEmail: this.fromEmail }; } async init(config) { var _a; this.transporter = nodemailer_1.default.createTransport({ host: config.host, port: config.port, secure: (_a = config.secure) !== null && _a !== void 0 ? _a : false, auth: { user: config.auth.user, pass: config.auth.pass, }, }); this.fromEmail = config.auth.user; await this.transporter.verify(); } async run(args) { if (!this.transporter || !this.fromEmail) { throw new Error("Mailer plugin is not initialized."); } const info = await this.transporter.sendMail({ from: this.fromEmail, to: args.to, subject: args.subject, text: args.text, html: args.html, attachments: args.attachments, }); return `📬 Email sent: ${info.messageId}`; } } exports.default = MailerPlugin;