UNPKG

ikmail

Version:

A tiny librairy to send emails with nodejs, using Infomaniak smtp service. Using modules.

34 lines (29 loc) 748 B
import { createTransport } from 'nodemailer'; export class Mailer { constructor(mail, password) { this.mail = mail this.transporter = createTransport({ host: 'mail.infomaniak.com', port: 465, secure: true, auth: { user: mail, pass: password } }); } send(to, name, subject, html, callback) { this.transporter.sendMail({ from: name + '<' + this.mail + '>', to: to, subject: subject, html: html }, (err, info) => { if(err) return callback('error', err) if(info.accepted[0] == to & info.rejected.length == 0 & info.response.includes('Ok')) { return callback('sended', info) } return callback('retry', info) }) } }