Module files: Use Npm to download nodemailer, a third-party module by Andris Reinman

Modified his module to generate a js file:

// Import modules

const nodemailer = require("nodemailer");

// Create an object

let obj = {

transporter: nodemailer.createTransport({

service: "qq".// Operator qq mailbox netease //

port: 465.secure: true.auth: {

user: "**********@qq.com".// Sender's email address

pass: "* * * * * * * * * * * * * * *" // POP3 authorization code}}),// Send a parameter (email address, content)

send: function(mail, content) {

mailOptions = {

// Sender's email address

from: '"Hello World~" <***********@qq.com>'.to: mail,

subject: content,

text: content,

html: "<h1>" + content + "</h1>"

};

this.transporter.sendMail(mailOptions, (error, info) = > {

if (error) {

return console.log(error);

}

console.log("Message sent: %s", info.messageId); }); }};// Throw an object to receive

module.exports = obj;
Copy the code

 

// Create a new js file to call the module

const sendMassage = require("./send.js");

sendMassage.send("*********@qq.com"."Hello World~");
Copy the code

Run this js file to send email to each other