|
|
@@ -0,0 +1,45 @@
|
|
|
+const nodemailer = require('nodemailer')
|
|
|
+
|
|
|
+class emali {
|
|
|
+ constructor () {
|
|
|
+ this._host = 'mail.1473.cn'
|
|
|
+ this._port = 25
|
|
|
+ this._user = 'admin@1473.cn'
|
|
|
+ this._pass = 'ssti-1'
|
|
|
+ this._captcha = Math.floor(Math.random()*9000)+1000
|
|
|
+ }
|
|
|
+ main (_email, callback) {
|
|
|
+ const _captcha = Math.floor(Math.random()*9000)+1000
|
|
|
+ let transporter = nodemailer.createTransport({
|
|
|
+ host: this._host, //邮箱服务器地址
|
|
|
+ port: this._port, // SMTP 端口
|
|
|
+ secureConnection: false, // 使用 SSL
|
|
|
+ auth: {
|
|
|
+ user: this._user,
|
|
|
+ pass: this._pass
|
|
|
+ },
|
|
|
+ tls: {
|
|
|
+ // do not fail on invalid certs
|
|
|
+ rejectUnauthorized: false
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ let mailOptions = {
|
|
|
+ from: this._user, // 发件地址
|
|
|
+ to: `${_email}`, // 收件列表
|
|
|
+ subject: '雨云科技', // 标题
|
|
|
+ //text和html两者只支持一种
|
|
|
+ html: `验证码:<b>${_captcha}</b>,请不要告诉别人` // html 内容
|
|
|
+ };
|
|
|
+
|
|
|
+ // send mail with defined transport object
|
|
|
+ transporter.sendMail(mailOptions, function(error, info){
|
|
|
+ if(error){
|
|
|
+ callback(error, false)
|
|
|
+ }
|
|
|
+ callback(_captcha, true)
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+module.exports = emali;
|