Is there an equivalent nodejs PHP mail () function

I come from the world of PHP, and I'm used to using mail () to send quick diagnostic emails on occasion. Is there a module or method in the standard NodeJS library, which is roughly equivalent to this?

+4
source share
2 answers

Nodemailer is a popular, stable and flexible solution:

Full usage looks something like this (the top bit is just configured, so you will only need to do this once for the application):

var nodemailer = require("nodemailer"); // create reusable transport method (opens pool of SMTP connections) var smtpTransport = nodemailer.createTransport("SMTP",{ service: "Gmail", auth: { user: " gmail.user@gmail.com ", pass: "userpass" } }); // setup e-mail data with unicode symbols var mailOptions = { from: "Fred Foo ✔ < foo@blurdybloop.com >", // sender address to: " bar@blurdybloop.com , baz@blurdybloop.com ", // list of receivers subject: "Hello ✔", // Subject line text: "Hello world ✔", // plaintext body html: "<b>Hello world ✔</b>" // html body } // send mail with defined transport object smtpTransport.sendMail(mailOptions, function(error, response){ if(error){ console.log(error); }else{ console.log("Message sent: " + response.message); } // if you don't want to use this transport object anymore, uncomment following line //smtpTransport.close(); // shut down the connection pool, no more messages }); 
+6
source

Sure:

 const nodemailer = require('nodemailer'); const transporter = nodemailer.createTransport({sendmail: true}, { from: ' no-reply@your-domain.com ', to: ' your@mail.com ', subject: 'test', }); transporter.sendMail({text: 'hello'}); 

Also see Configuring sendmail inside the docker container

+4
source

All Articles