node发邮件
Posted fm060
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了node发邮件相关的知识,希望对你有一定的参考价值。
/* var request = require(‘superagent-charset‘); var superagent = require(‘superagent‘); request(superagent); var cheerio = require(‘cheerio‘); var mysql = require(‘mysql‘); const pool = mysql.createPool({ host : ‘localhost‘, // 数据库地址 user : ‘root‘, // 数据库用户 password : ‘root‘, // 数据库密码 database : ‘qq‘ // 选中数据库 }) const query = function( sql, values ) { return new Promise(( resolve, reject ) => { pool.getConnection(function(err, connection) { if (err) { reject(err) } else { connection.query(sql, values, ( err, rows) => { if ( err ) { reject(err) } else { resolve(rows) } connection.release() }) } }) }) }*/ /*var Crawler = require("crawler"); var c = new Crawler({ maxConnections: 1000, // This will be called for each crawled page callback: function(error, res, done) { if (error) { console.log(error); } else { var $ = res.$; console.log($(‘.center‘).text()) $(‘.seller-info-body .item‘).each(function(idx, element) { var $element = $(element); //var li="<li><a href=‘"+ul+$element.find(‘.t1 a‘).attr(‘href‘)+"‘"+$element.find(‘.t1 a‘).text()+"</li>"; var plink = $element.text(); console.log(plink); }); }; } });*/ /*for(var i=188775100;i<188775250;i++){ let url = ‘https://www.meituan.com/xiuxianyule/‘+i c.queue(url) }*/ //c.queue(‘http://qq.qqdna.com/qqlist/beijing_100011.html‘); //http://qq.qqdna.com/qqlist/beijing_100011.html /*let arr query(‘SELECT * from beijingtop‘,function(err, rows, fields){ arr = rows arr.forEach((val,i)=>{ if(i>3&&i<5){ let url = "http://qq.qqdna.com/qqlist/beijing_"+val.qq+".html" sup(url) } }) }) function sup(url){ console.log(url) superagent.get(url).end(function(error, mes) { if (error) { console.log("出问题了:" + error) } else { var $ = cheerio.load(mes.text); let text = $(‘table‘).text() let arr = text.split(‘ ‘) arr.forEach((val,i)=>{ if(val.length==9){ console.log(val) //let sql = "insert into beijing (qq) values(‘"+val+"‘)" } }) } }) }*/ /*var url = "http://qq.qqdna.com/qqlist/beijing_100011.html" superagent.get(url).end(function(error, mes) { if (error) { console.log("出问题了:" + error) } else { var $ = cheerio.load(mes.text); let text = $(‘table‘).text() let arr = text.split(‘ ‘) console.log(arr) arr.forEach((val,i)=>{ if(val.length==9){ console.log(val) let sql = "insert into beijing (qq) values(‘"+val+"‘)" } }) } })*/ //http://qq.qqdna.com/city/beijing/beijing.php /*var url = "http://qq.qqdna.com/city/beijing/beijing.php" superagent.get(url).end(function(error, mes) { if (error) { console.log("出问题了:" + error) } else { var $ = cheerio.load(mes.text); $(‘.all ul li‘).each(function(){ console.log($(this).text()) let qq = $(this).text() let sql = "insert into beijingtop (qq) values(‘"+qq+"‘)" query(sql) }) } })*/ /*const {Builder, By, Key, until, Button} = require("selenium-webdriver"); let broswer = new Builder().forBrowser(‘chrome‘).build() broswer.get(‘https://www.meituan.com/xiuxianyule/188775119‘) // console.log(By.className(‘seller-name‘)) setTimeout(()=>{ console.log(2222) broswer.getTitle().then(b=>{console.log(b)}); broswer.getCurrentUrl().then(b=>{console.log(b)}); },5000) broswer.findElement(By.name(‘seller-name‘)) broswer.getTitle().then(b=>{console.log(b)}); broswer.getCurrentUrl().then(b=>{console.log(b)}); broswer.quit() // 表示关闭浏览器 */ //drive.close()表示关闭当前窗口 var html = ‘<div style="background-color:#ECECEC; padding: 35px;">‘+ ‘<table cellpadding="0" align="center" style="width: 600px; margin: 0px auto; text-align: left; position: relative; border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; font-size: 14px; font-family:微软雅黑, 黑体; line-height: 1.5; box-shadow: rgb(153, 153, 153) 0px 0px 5px; border-collapse: collapse; background-position: initial initial; background-repeat: initial initial;background:#fff;">‘+ ‘<tbody>‘+ ‘<tr>‘+ ‘<th valign="middle" style="text-align: center;height: 25px; line-height: 25px; padding: 15px 35px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #C46200; background-color: #FEA138; border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px;">‘+ ‘<font face="微软雅黑" size="5" style="color: rgb(255, 255, 255);">一心游戏应用中心</font>‘+ ‘</th>‘+ ‘</tr>‘+ ‘<tr>‘+ ‘<td>‘+ ‘<div style="padding:25px 35px 40px; background:url("http://www.fanxingol.com/android/ftmy/images/0_01.jpg");">‘+ ‘<h2 style="margin: 5px 0px; "><font color="#333333" style="line-height: 20px; "><font style="line-height: 22px; " size="4">亲爱的 <?php echo $email;?>:</font></font></h2>‘+ ‘<p>首先感谢您查看给你推荐的游戏!<br>请您在使用我们的APP时,遵守当地法律法规。<br>适度游戏益脑,沉迷游戏伤身,合理安排时间,享受健康生活。<br>一心游戏,一心一意做游戏。<br><a href="#">安卓游戏下载</a><br><a href="#">ios游戏下载</a><br><img src="data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAA8AAD/4QMpaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjAtYzA2MCA2MS4xMzQ3NzcsIDIwMTAvMDIvMTItMTc6MzI6MDAgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+IDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bXBN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vfI69uAOdVl0uSqKWo1U3VxM8P1qBc5BdA4RbzvEY2McIjfU19c5+kYMHqdy/bnfcV824esjcavcYBblXG4FM5BqZhSLYFgajBTknV0xxZ1DxkZiifUzp2655JdoBV5t5eleniopAiRLpTMnTZYBGorc8h2e6zXPsqTcvw2JSh5RlS1ncNBf0So02494j+kXScd2IG9Dbk0x9atkI2l82qraMDgctyhaDTDQK5VNwyqpxiBl0Pa2LJ0lh3JL27ceGjfef8AKq+p4SvF6mHa2Mwx3IXZsnas76gCOrwbD5PHL6R5fb8WUTYblacGlAAj7GeHvaiAP//Z">‘+ ‘<p align="right">一心游戏! 官方团队</p ><img border="0" width="364" height="482" style="display:block;" src="https://xinnuo.e.zaobang.com/dynamic?taskId=9900780&companyId=43&ruleId=385&combinationId=238075&bannerId=141&create_at=1544497323&be=$_bto$&images=http%3A%2F%2Fxinnuo.images.vrm.cn%2F2018%2F619%2F152534463.jpg%3FimageView2%2F1%2Fw%2F750%2Fh%2F920%7CimageMogr2%2Fcrop%2F%21364x482a386a0">‘+ ‘<p align="right"><?php date("Y年m月d日 H:i:s");?></p >‘+ ‘</div>‘+ ‘</td>‘+ ‘ </tr>‘+ ‘</tbody>‘+ ‘</table>‘+ ‘</div>‘ var nodemailer = require(‘nodemailer‘) var sendmail = function (mail) { //邮件发送 var transporter = nodemailer.createTransport({ service: ‘163‘, auth: { user: ‘[email protected]‘,//你的163邮箱账号 pass: ‘‘//你的163邮箱密码 } }); var mailOptions = { from: ‘[email protected]‘, // sender address to:mail, // list of receivers subject: ‘测试邮件‘, // Subject line text: ‘Nodejs之邮件发送‘, // plaintext body html:html }; transporter.sendMail(mailOptions, function(error, info){ if(!error){ console.log(‘发送成功‘) }else{ console.log(error); } }); }; sendmail(‘[email protected]‘)
以上是关于node发邮件的主要内容,如果未能解决你的问题,请参考以下文章
使用来自 node.js 的 AWS SES 在邮件中上传 .jpg 图像附件