After the project was released, the NODEJS process encountered an unpredictable bug, and after the crash, we wanted to notify the developer by mail. It's convenient for us to find problems.
Just have a plug-in, easy to use, recorded here. The plugin name is Nodemailer. Address https://github.com/andris9/Nodemailer/.
Record the use of their own problems encountered in the process, I often use the QQ mailbox, but the example of the test Gmail, then this nodemailer also support what services.
There is an introduction in Nodemailer-wellknown. Here is my implementation code
//for exceptions, the administrator who sent the message to a specific QQ mailbox has found a problemvarServerconfig = require ('.. /shared/config/serverconfig ');varNodemailer = require (' Nodemailer '));functionErrormail (content) {varTransporter =Nodemailer.createtransport ({service:"QQ", auth: {user:ServerConfig.MailUser, Pass:ServerConfig.MailPass}}); varCurdate =NewDate (); varSubject = "Mainserver Crash" +curdate; varhtml = ' <b> ' + content + ' </b> '; varMailoptions ={from:ServerConfig.MailUser, To:ServerConfig.MailUser, Subject:subject, text:' Mail test content ', html:html}; Transporter.sendmail (Mailoptions,function(error,info) {if(Error) Console.log (error); ElseConsole.log (' Message Sent: ' +info.response); });} Module.exports.ErrorMail= Errormail;View Code
Where Serverconfig is configured to send mailboxes.
var Serverconfig = { ' [email protected] ', ' XXXX '}
Nodejs process crashes sending mail