0

I am creating an inbox with SMTPServer like Gmail or similar, my question is can I receive messages from another provider?

for example if a Gmail user sends an email to a user registered in my SMTPServer this could see that email? I only tested sending from nodemailer to my SMTP server.

import { SMTPServer } from "smtp-server";
import { simpleParser } from "mailparser";
const server = new SMTPServer({
  onData(stream, session, callback) {
    simpleParser(stream, (err, main) => {
      if (err) {
        return callback(err);
      }
      console.log(main);
      callback();
    });
  },
  onAuth(auth, session, callback) {
    // mongo atlas user
    if (auth.username !== "example@localhost.com" || auth.password !== "1234") {
      return callback(new Error("Invalid username or password"));
    }
    callback(null, { user: auth }); // where 123 is the user id or similar property
  },
});

server.on("error", (err) => {
  console.log("Error %s", err.message);
});

server.listen(490, () => {
  console.log("Connected");
});

nodemailer idea


"use strict";
import nodemailer from "nodemailer";

async function main() {

  let transporter = nodemailer.createTransport({
    host: "gmail",
    port: 490,
    secure: false,
    auth: {
      user: "example@gmail.com",
      pass: "1234",
    },
    tls: {
      rejectUnauthorized: false,
    },
  });

  
  let info = await transporter.sendMail({
    from: '"Foo " <example@gmail.com>',
    to: "example@localhost.com", // SMTP mongo user
    subject: "Hello ✔", 
    text: "Hello world?", 
    html: "<b>Hello world?</b>", 
  });

  console.log("Message sent: %s", info.messageId);
  // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
}

main().catch(console.error);
Neyunse
  • 105
  • 5

0 Answers0