Receiving email in Node.js

EmailSmtpnode.jsPop3

Email Problem Overview


I see a lot of Node.js modules out there that sends mail through SMTP.

But is there a module to receive mail?

Email Solutions


Solution 1 - Email

You are looking for an e-mail client library. Currently, there are 2 options (as mentioned here):

I never used them before, but usage is pretty straight forward (according to the docs). node-imap seems to be the more stable library and it has been tested against gmail. If IMAP is an option in your environment, i'd stick with node-imap.

Solution 2 - Email

The Mailin module allows you to receive emails, parse them and post them to a webhook of your choice. It is based on simplesmtp. It also checks the dkim and spf, computes a spamassassin score and determines the message language.

Even if it does not fit your needs exactly, you can have a look at the code, it might help you. (Disclaimer: I am the maintainer of Mailin)

Solution 3 - Email

Solution 4 - Email

The solution that I found is mail-listener2. I was able to get up and running with this in just a few minutes, it ties in node-imap and mailparser nicely out of the box.

Solution 5 - Email

This is coming so so late but may help others with similar question

Basically you can you mailgun to receive emails from user. Case scenario of messaging the admin from contact form

You can simply use mailgun in nodemailer

Go to mailgun and configure your api_key, domain and authorized the recipient mail address(the mail address you want to be receiving user's mails on).

const nodemailer = require('nodemailer');
const mailgun = require('nodemailer-mailgun-transport');

const transporter = nodemailer.createTransport(mailgun({
    auth: {
        api_key: process.env.API_KEY,
        domain: process.env.DOMAIN,
    }
}));

const mailOptions = {
    from: "[email protected]", //user's mail address, you can make it dynamic from contact form
    to: "[email protected]", //the mail address you authorized in mailgun (receipient mail address)
    subject: "Test", //maybe from contact for
    text: "message from one of your users"  //maybe from contact for
};

transporter.sendMail(mailOptions, (error, response) => {
    if (error) {
        console.log(error);
    } else {
        console.log("Message Sent!");
    }
});

You can google how to get mailgun api_key, domain and authorized recipient mail address

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionfoobarView Question on Stackoverflow
Solution 1 - EmailschaermuView Answer on Stackoverflow
Solution 2 - EmailFlolagaleView Answer on Stackoverflow
Solution 3 - EmailDrew LeSueurView Answer on Stackoverflow
Solution 4 - EmailAnthonyView Answer on Stackoverflow
Solution 5 - EmailmozeyView Answer on Stackoverflow