**Install nodemailer **
npm install nodemailer --save
**Second, the call **
var nodemailer = require("nodemailer");
//Open an SMTP connection pool
var smtpTransport = nodemailer.createTransport("SMTP",{
host: "smtp.qq.com", // The host
secureConnection: true, //Using SSL
port: 465, //SMTP port
auth: {
user: "[email protected]", // account
pass: "xxxxxxxx" // password
}
});
//Set email content
var mailOptions = {
from: "Fred Foo <[email protected]>", //Send an address
to: "[email protected], [email protected]", //Receipt list
subject: "Hello world", // The title
html: "<b>thanks a for visiting!</b> Hello, world! " //HTML content
}
//Send E-mail
smtpTransport.sendMail(mailOptions, function(error, response){
if(error){
console.log(error);
}else{
console.log("Message sent: " + response.message);
}
smtpTransport.close(); //If not, close the connection pool
});
**Common mistakes **
{ [AuthError: Invalid login - 454 Authentication failed, please open smtp flag first!]
name: 'AuthError',
data: '454 Authentication failed, please open smtp flag first!',
stage: 'auth' }
Error cause: the service was not set on the account Solution: QQ mailbox -> Settings - > Account - > Open service: POP3/SMTP service
{ [SenderError: Mail from command failed - 501 mail from address must be same as authorization user]
name: 'SenderError',
data: '501 mail from address must be same as authorization user',
stage: 'mail' }
Error reason: the sending account is different from the authenticated account