企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# koa搭建邮箱通知 基础包 > nodemailer 核心代码如下: ~~~ /** * Created by Administrator on 2017/8/5. */ let nodeamiler = require('nodemailer'); let transporter = nodeamiler.createTransport({ host: 'smtp.sina.com', secureConnection: true, auth: { user: 'gitvip@sina.com', pass: 'king1234' } }); exports.sendMail = function (options) { transporter.sendMail(options, function(error, info){ if(error){ console.log(error) isSend = false } else { console.log('Message sent: ' + info.response) isSend = true } }); } ~~~ 在路由处调用 ~~~ /** * Created by Administrator on 2017/8/5. */ const db = require('./../orm/data'); const Mail = require('./../orm/email'); let nodeamiler = require('nodemailer'); let getArticle = exports.getArticle = function *() { this.body = 'hell word getarticle' } let findAll = exports.findAll = function *() { let query = { id: 1 } let data = yield db.findAll(query); this.body = data } let findOne = exports.findOne = function *() { let query = { id: 1 } let data = yield db.findOne(query); this.body = data } let htmlTemplate = `<p style="color: blue">测试邮箱,你好小龙</p>`; let options = { from: 'gitvip@sina.com', to: '2578038306@qq.com', subject: 'kingEND', text: '你好啊', html: htmlTemplate } let sendEmail = exports.sendEmail = function *() { Mail.sendMail(options) } exports.register = function (router) { router.get('/api/getArticle', getArticle) router.get('/api/findAll', findAll) router.get('/api/findOne', findOne) router.get('/api/sendEmail', sendEmail) }; ~~~