The function is timed every day, and the intercepted images are sent automatically via email. Description code comments are very detailed, do not do more instructions, the need for friends to view the code, The main file mail.js, file Capturepart1.js,capturepart2.js,capturepart3.js, here only shows capturepart1.js the other two similar. It is important to note that there are login rights to the site must set a cookie, need to intercept high-quality pictures, the interception time must be set longer. mail.js/******************************************************************************************************* * Scheduled Email feature Description: * node. JS Prerequisite Installation module: Node_modules-->phantomjs,nodemailer , node-schedule,moment * Involved JS file: Route-->mail.js,public-->js-->capturepart1.js,capturepart2.js,capturepar T3.js * Save Address: Public-->images-->mainpage.jpeg (1600*4200) * url:http://www.***********.com * The main idea of the program: * (1) phantomjs--> Reference http://phantomjs.org/* (2) nodemailer send mail--reference HTTPS://WWW.NPM Js.com/package/nodemailer * (3) Node-schedule Timing--Reference Https://www.npmjs.com/package/node-schedule * Note: * Change the sender server modify SMTP * Change recipient please modify variable receiver * ChangeEmail content Please modify the variable HTML * Change the message attached pictures and accessories please modify attachments * Change function please modify Public-->js-->server.js * To change the timing function, modify the variable rule *------sweety******************************* Component Introduction starts var schedule = require (" Node-schedule "), var path = require (' path '), var childprocess = require (' child_process '); var phantomjs = require (' Phantomjs '), var Nodemailer = require ("Nodemailer"), var moment = require ("moment");//Component Introduction End/*------------------------ --------------------------------------------------------------------------------------------------------------- -----*///Variable definition start var today; Today's start time var binpath = Phantomjs.path; Get Phantomjs.exe path var jspath = PROCESS.CWD () + "/public/js/"; Get Server.js directory var childargs;//capturepart3 ();//capturepart1 ();//variable definition end/*------------------------------------ --------------------------------------------------------------------------------------------------------*///Main program starts var rule = new schedule. Recurrencerule (); Schedule Timer Rule.hour = 11;rule.minute = 0;rule.second = 0; Timer rule setting (11-point trigger event per day) var j = schedule.schedulejob (rule, function () {var now = moment (); Today = Now.clone (). Add ( -1, ' Days '). Format (' Yyyy-mm-dd '); CapturePart1 (); Trigger event (message sending function is included in event)});//Main program end//*----------------------------------------------------------------------------- ----------------------------------------------------------------*///phantomjs Start (first) function CapturePart1 () { Childargs = [Path.join (Jspath, ' serverpart1.js '),//server.js ' https://www.hao123.com '//URL to be ]; Childprocess.execfile (BinPath, Childargs, function (err, stdout, stderr) {if (err) {Console.log (E RR); Print error message}else{console.log ("Captured Part1 successful!");//print correct information capturePart2 (); } });} Phantomjs End(first)//phantomjs start (second picture) function CapturePart2 () {Childargs = [Path.join (Jspath, ' serverpart2.js '),//serv Er.js path ' https://www.hao123.com '//URL to be]; Childprocess.execfile (BinPath, Childargs, function (err, stdout, stderr) {if (err) {Console.log (E RR); Print error message}else{console.log ("Captured Part2 successful!");//print correct information capturePart3 (); } });} Phantomjs End (second photo)//phantomjs start (third) function CapturePart3 () {Childargs = [Path.join (Jspath, ' serverpart3.js '), Server.js path ' https://www.hao123.com '//URL to be]; Childprocess.execfile (BinPath, Childargs, function (err, stdout, stderr) {if (err) {Console.log (E RR); Print error message}else{console.log ("Captured Part3 successful!");//print correct information sent (); Trigger Send Message Event}}); Phantomjs End (third)/*------------------------------------------------------------------------------------------------------------------------------------------- ------*///nodemailer Send mail start function sent () {var imgPart1 = Fs.readfilesync (PROCESS.CWD () + "/public/images/ Mainpagepart1.jpeg "); Picture source var imgPart2 = Fs.readfilesync (PROCESS.CWD () + "/public/images/mainpagepart2.jpeg"); Picture source var imgPart3 = Fs.readfilesync (PROCESS.CWD () + "/public/images/mainpagepart3.jpeg"); Image source var smtptransport = Nodemailer.createtransport ("SMTP", {//Mail SMTP settings (SMTP must be turned on for outgoing mailbox server) host : "Smtp.xxxxx.com",//Host Secureconnection:false,//Do not use SSL PO rt:587,//SMTP port auth: {User: "[email protected]", User name pass: "xxxxxx"//password}); var html = ' <meta http-equiv= ' Content-type "content=" text/html; Charset=utf-8 "> ' + ' xx good:</br> ' + below for the "XXXX" Daily report (' +today+ ') content, please refer to </br> ' + ' (daily details please click <a hre f= "#" onclick= "Changedata ();" > Login Here </a> view) ' + ' </br> ' + ' ' + ' ' + ' ';//e-mail content (HTML code), IMG unique specified address pair Should CID (see Mailoptions set) var receiver = "[email protected]";//Recipient list var cc = "[EMAIL&NBSP;PROTECTED],[EMAIL&NBSP;PR Otected],[email protected] "; CC Person list var bcc = "[email protected],[email protected]"; BCC list var mailoptions = {//message content option settings from: ' <[email protected]> ',//Send Address//to: "[email protected]", to:receiver,//Recipient CC:CC, CC person BCC:BCC,//CC person Subject: "XXXX" Daily Report ("+today+") ",//Email subject text:" " XXXX "Daily report ("+today+") ",//PlainText body html:html,//html content attachments: [{ FileName: ' mainpagepart1.jpeg ',//Picture name Contents:imgpart1,//Image source CID: ' IMG1 '//Insert Picture ID},{filename: ' mainpagepart2.jpeg ',//Picture name con Tents:imgpart2,//Image source cid: ' Img2 '//Insert Picture identification},{ FileName: ' mainpagepart3.jpeg ',//Picture name CONTENTS:IMGPART3,//Image source CID: ' IMG3 '//Insert Picture identifier}]}; Smtptransport.sendmail (mailoptions, function (Error, Response) {//Send message if (error) {Console.log (error); Print error message}else{console.log ("Sent successful!!"); Print the correct Information}}); Nodemailer Send Message End Function Changedata () {}/*---------------------------------------------------------------------------------------------------------------------------------------------*/capturepart1.js// Phantomjsvar page = require (' webpage '). Create (), System = require (' System '), Address;page.viewportsize = {width:192 0, height:1080};p age.cliprect = {top:200, left:210, width:1680, height:1530};p age.customheaders={"Cookie": "Koa:sess =E*******=;KOA:SESS.SIG=PJADZTLAVTIO6-HAW1VNZZWRRM8 "};if (system.args.length = = = 1) {phantom.exit (1);} else {Addre SS = System.args[1]; Page.open (address, function (status) {});} SetTimeout (function () {Console.log (""); Console.log ("# # # STEP 5:close page and shutdown (with a delay)"); Page.render ('./public/images/mainpagepart1.jpeg ', {format: ' JPEG ', quality: ' 100 '}); Page.close (); SetTimeout (function () {phantom.exit (); }, 3000);}, 19000);
nodejs+ timed + Send mail