| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- "use strict";
- const nodemailer = require("nodemailer");
- let DEFAULT_DATA = {
- //from: '通知<webmaster@ikamaza.com>',
- from: 'Monitor<pcoloring@ikamaza.com>',
- to: "chengen@jccy-tech.com", // list of receivers
- subject: '无标题',
- text: "无内容", // plain text body
- //html: "<b>Hello world?</b>", // html body
- }
- async function send(mail) {
- let transporter = nodemailer.createTransport({
- host: "mail.ikamaza.com",
- port: 587,
- secure: false, // true for 465, false for other ports
- auth: {
- user: 'mailer', // generated ethereal user
- pass: 'Mailer@Jccy2017.', // generated ethereal password
- },
- });
- let data = JSON.parse(JSON.stringify(DEFAULT_DATA));
- data = Object.assign(data, mail);
- try {
- let info = await transporter.sendMail(data);
- console.log('Mail', data);
- console.log("Message sent: %s", info.messageId);
- // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
-
- // Preview only available when sending through an Ethereal account
- console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
- return info;
- } catch(err) {
- console.error(err);
- }
-
- }
- module.exports = {
- send,
- }
- if (require.main == module) {
- send({
- subject: 'hello:' + new Date(),
- text: 'hello',
- //attachments: [{
- // path: './mail.js',
- //}]
- }).then(console.log).catch(console.error);
- }
|