NPM-sparkpost境外邮件提供商的三方包

安装

1
npm install sparkpost

全部代码

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const SparkPost = require('sparkpost');
const uuidV4 = require('uuid/v4');
const moment = require('moment');
const uuid = uuidV4();
let logger_email = require('../Log/log.js').email;

//-------------------------KEY---------------------------//
const apiKey = 'apikey';
const from = '发件人邮箱 xxx@xxx.xxx.net';
const client = new SparkPost(apiKey);
const driver = 'sparkpost';
//------------------------------------------------------//

//定义空对象
var emailer_sparkpost = {};

/**
*
* @param code 验证码
*/
emailer_sparkpost.JointZhushuAPP = function(code) {
const now_data = moment().format('YYYY-MM-DD HH:mm:ss');
let html = `
您的註冊验证码是:**${code}**,15分钟内有效,请及时使用。
${now_data}
xxxAPP `;
return html;
};

/**
* 使用sparkpost发送邮箱验证码
* @param emailaddr 邮箱地址
* @param title 发送的标题
* @param content 发送的数据
* @param callback 回调函数,回调成功或者失败
*/
emailer_sparkpost.sendEmail = function(emailaddr,title, content , callbackval) {
logger_email.info('发送地址:'+ emailaddr);
logger_email.info('发送标题:'+ title);
logger_email.info('发送内容:'+ content);
const recipients = [
{ address: emailaddr },
];
client.transmissions.send({
options: {
sandbox: false
},
content: {
from: from,
subject: title,
html: content,
},
recipients: recipients,
})
.then(data => {
callbackval(null);
})
.catch(err => {
logger_email.error(err);
callbackval(err);
});
};


module.exports = emailer_sparkpost;
  • 版权声明: 本博客所有文章,未经许可,任何单位及个人不得做营利性使用!转载请标明出处!如有侵权请联系作者。
  • Copyrights © 2015-2024 翟天野

请我喝杯咖啡吧~