Mail.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. 'use strict';
  2. let NodeMailer = Editor.require('packages://hot-update-tools/node_modules/nodemailer');
  3. let Fs = require('fire-fs');
  4. module.exports = {
  5. _service: 'qq',
  6. _user: 'xu_yanfeng@qq.com',
  7. _pass: 'fizyosflryzlbege',
  8. setMailServiceInfo (user, pass) {
  9. this._user = user;
  10. this._pass = pass;
  11. },
  12. isArray (object) {
  13. return object && typeof object === 'object' && Array === object.constructor;
  14. },
  15. sendMail (version, content, people, sendCb) {
  16. let transporter = NodeMailer.createTransport({
  17. service: this._service,
  18. auth: {
  19. user: this._user,
  20. pass: this._pass, // 授权码,通过QQ获取
  21. },
  22. });
  23. let sendPeople = ['xu_yanfeng@126.com'];
  24. if (this.isArray(people)) {
  25. for (let k in people) {
  26. sendPeople.push(people[k]);
  27. }
  28. } else if (typeof people === 'string') {
  29. sendPeople.push(people);
  30. }
  31. let data = Fs.readFileSync(Editor.url('packages://hot-update-tools/mail/MailTemp.html'), 'utf-8');
  32. if (data.indexOf('%version%') !== -1) {
  33. data = data.replace('%version%', version);
  34. }
  35. if (data.indexOf('%content%') !== -1) {
  36. data = data.replace('%content%', content);
  37. }
  38. let mailOptions = {
  39. from: this._user, // 发送者
  40. to: sendPeople.toString(), // 接受者,可以同时发送多个,以逗号隔开
  41. subject: '测试版本 发布通知-v' + version, // 标题
  42. text: 'Hello world', // 文本
  43. html: data,
  44. };
  45. transporter.sendMail(mailOptions, (err, info) => {
  46. if (sendCb) {
  47. sendCb();
  48. }
  49. if (err) {
  50. console.log(err);
  51. }
  52. });
  53. },
  54. };