add send mail lib
This commit is contained in:
parent
69d560a21a
commit
e094b97f10
@ -9,7 +9,9 @@ const config = require('./config.json');
|
|||||||
const mysql = require('./libs/mysql_pool');
|
const mysql = require('./libs/mysql_pool');
|
||||||
const so = require('./libs/storeObject');
|
const so = require('./libs/storeObject');
|
||||||
const mem = require('./libs/memcache_lib');
|
const mem = require('./libs/memcache_lib');
|
||||||
|
const sendmail = require('./libs/sendmail');
|
||||||
|
|
||||||
|
// init memcached connection
|
||||||
mem.host = 'dyn.trj.tw';
|
mem.host = 'dyn.trj.tw';
|
||||||
mem.port = 24002;
|
mem.port = 24002;
|
||||||
mem.connect();
|
mem.connect();
|
||||||
|
@ -16,5 +16,13 @@
|
|||||||
"port": 27017,
|
"port": 27017,
|
||||||
"dbname": "lora"
|
"dbname": "lora"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"smtp": {
|
||||||
|
"sys_mail": "admin@localhost",
|
||||||
|
"host": "localhost",
|
||||||
|
"port": 587,
|
||||||
|
"secure": false,
|
||||||
|
"user": "admin",
|
||||||
|
"pass": "pass"
|
||||||
}
|
}
|
||||||
}
|
}
|
34
server-api/libs/sendmail.js
Normal file
34
server-api/libs/sendmail.js
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
const nodemailer = require('nodemailer');
|
||||||
|
const config = require('../config.json');
|
||||||
|
|
||||||
|
module.exports = async(toMail, type = 'forgotpass', data = []) => {
|
||||||
|
let transporter = nodemailer.createTransport({
|
||||||
|
host: config.smtp.host,
|
||||||
|
port: config.smtp.port,
|
||||||
|
secure: config.smtp.secure, // secure:true for port 465, secure:false for port 587
|
||||||
|
auth: {
|
||||||
|
user: config.smtp.user,
|
||||||
|
pass: config.smtp.pass
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// setup email data with unicode symbols
|
||||||
|
let mailOptions = {
|
||||||
|
from: config.smtp.sys_mail, // sender address
|
||||||
|
to: toMail, // list of receivers
|
||||||
|
subject: 'Hello ✔', // Subject line
|
||||||
|
text: 'Hello world ?', // plain text body
|
||||||
|
html: '<b>Hello world ?</b>' // html body
|
||||||
|
};
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
// send mail with defined transport object
|
||||||
|
transporter.sendMail(mailOptions, (error, info) => {
|
||||||
|
if (error) {
|
||||||
|
return reject(error);
|
||||||
|
}
|
||||||
|
// console.log('Message %s sent: %s', info.messageId, info.response);
|
||||||
|
return resolve(info);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -14,6 +14,7 @@
|
|||||||
"koa-static": "^3.0.0",
|
"koa-static": "^3.0.0",
|
||||||
"memcached": "^2.2.2",
|
"memcached": "^2.2.2",
|
||||||
"mongoose": "^4.10.4",
|
"mongoose": "^4.10.4",
|
||||||
"mysql": "^2.13.0"
|
"mysql": "^2.13.0",
|
||||||
|
"nodemailer": "^4.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,6 +159,9 @@ router
|
|||||||
c.serr = err;
|
c.serr = err;
|
||||||
throw 'SE0005';
|
throw 'SE0005';
|
||||||
}
|
}
|
||||||
|
c.body = {
|
||||||
|
record: []
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@ -415,6 +415,10 @@ negotiator@0.6.1:
|
|||||||
version "0.6.1"
|
version "0.6.1"
|
||||||
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9"
|
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9"
|
||||||
|
|
||||||
|
nodemailer@^4.0.1:
|
||||||
|
version "4.0.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-4.0.1.tgz#b95864b07facee8287e8232effd6f1d56ec75ab2"
|
||||||
|
|
||||||
object-assign@^4.0.1:
|
object-assign@^4.0.1:
|
||||||
version "4.1.1"
|
version "4.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
|
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
|
||||||
|
Loading…
Reference in New Issue
Block a user