mail.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. "use strict";
  2. const nodemailer = require("nodemailer");
  3. let DEFAULT_DATA = {
  4. //from: '通知<webmaster@ikamaza.com>',
  5. // from: 'PCOLORING<pcoloring@ikamaza.com>',
  6. from: "Monitor<pcoloring@kizimail.com>",
  7. to: "chengen@jccy-tech.com", // list of receivers
  8. subject: "无标题",
  9. text: "无内容", // plain text body
  10. //html: "<b>Hello world?</b>", // html body
  11. };
  12. async function send(mail) {
  13. let transporter = nodemailer.createTransport({
  14. // host: 'mail.ikamaza.com', // 废弃
  15. host: "mail.kizimail.com",
  16. port: 587,
  17. secure: false, // true for 465, false for other ports
  18. auth: {
  19. // user: 'mailer', // generated ethereal user
  20. // pass: 'Mailer@Jccy2017.', // generated ethereal password
  21. user: "pcoloring@kizimail.com", // generated ethereal user
  22. pass: "0,k)Mf25T#AX3*=", // generated ethereal password
  23. },
  24. });
  25. let data = JSON.parse(JSON.stringify(DEFAULT_DATA));
  26. data = Object.assign(data, mail);
  27. try {
  28. let info = await transporter.sendMail(data);
  29. console.log("Mail", data);
  30. console.log("Message sent: %s", info.messageId);
  31. // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
  32. // Preview only available when sending through an Ethereal account
  33. console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
  34. return info;
  35. } catch (err) {
  36. console.error(err);
  37. }
  38. }
  39. module.exports = {
  40. send,
  41. };
  42. if (require.main == module) {
  43. send({
  44. to: "guoziyun@jccy-tech.com",
  45. subject: "hello:" + new Date(),
  46. text: "hello new",
  47. //attachments: [{
  48. // path: './mail.js',
  49. //}]
  50. })
  51. .then(console.log)
  52. .catch(console.error);
  53. }