import htmlToText from 'html-to-text' import nodemailer from 'nodemailer' import { resolveContent } from 'nodemailer/lib/shared' export default class EmailService { static getTransporter() { if (process.env.SMTP_HOST == undefined || process.env.SMTP_PORT == undefined) { throw new Error("Invalid SMTP config") } return nodemailer.createTransport({ host: process.env.SMTP_HOST, port: parseInt(process.env.SMTP_PORT), secure: process.env.SMTP_SECURE == 'true', auth: { user: process.env.SMTP_USERNAME, pass: process.env.SMTP_PASSWORD, } }) } static send(to: string, subject: string, html: string) { return new Promise(resolve => { console.log('to', to) console.log('subject', subject) console.log('html', html) // this.getTransporter().sendMail({ // from: '"Forum des associations - Espace Condorcet Centre Social" ', // to, // subject, // text: htmlToText.fromString(html, { wordwrap: 130 }), // html, // }).then(info => { // console.log("Message sent: %s", info.messageId); // console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info)); // resolve(info) // }).catch(err => { // console.error(err) // }) }) } }