UNPKG

create-emails

Version:

A Node.js API to create email accounts using cPanel’s API. This package automates email account creation, making it useful for hosting services, SaaS applications, and businesses that need email provisioning.

52 lines (43 loc) 1.41 kB
import Imap from "imap"; import { simpleParser } from "mailparser"; const imap = new Imap({ user: `testemail1@jamfortetech.com`, password:"testemailPassword1!", host: "jamfortetech.com", // Replace with your IMAP server port: 993 , tls: true, tlsOptions: { rejectUnauthorized: false }, // tls: { // rejectUnauthorized: true, // Ensure that the server certificate is validated // }, }); imap.once("ready", function () { console.log("IMAP Ready!"); imap.openBox("INBOX", true, function (err, box) { if (err) throw err; imap.search(["ALL"], function (err, results) { if (err) throw err; if (!results.length) return console.log("No emails found"); const f = imap.fetch(results, { bodies: "" }); f.on("message", function (msg, seqno) { msg.on("body", function (stream) { simpleParser(stream, (err, parsed) => { if (err) return console.log("Parse error:", err); console.log("Email subject:", parsed.subject); }); }); }); f.once("end", function () { console.log("Done fetching emails"); imap.end(); }); }); }); }); imap.once("error", function (err) { console.log("IMAP error:", err); }); imap.once("end", function () { console.log("Connection ended"); }); imap.connect();