diff --git a/config.dev.js b/config.dev.js index 879ad8a..241a59e 100644 --- a/config.dev.js +++ b/config.dev.js @@ -66,10 +66,20 @@ module.exports = { blockApi: 'http://127.0.0.1:7101', // 报错重启时的邮件发送 mails: { + type: 'smtp', // smtp | sendmail sendmailPath: '/usr/sbin/sendmail', - user: 'aelf.scan@aelf.io', // generated ethereal user + user: 'scan@domain.io', // generated ethereal user from: 'AElf scan ', to: ['test@mail.com'], - subject: 'error happened when scanning' + subject: 'error happened when scanning', // mail subject + smtpConfig: { + host: "smtp.domain.com", + port: 465, + secure: true, + auth: { + user: "monitor@domain.com", + pass: "password", + } + } } }; diff --git a/config.prod.js b/config.prod.js index 266008d..95504ed 100644 --- a/config.prod.js +++ b/config.prod.js @@ -57,10 +57,20 @@ module.exports = { }, blockApi: 'http://127.0.0.1:7101', mails: { + type: 'smtp', // smtp | sendmail sendmailPath: '/usr/sbin/sendmail', - user: 'aelf.scan@aelf.io', // generated ethereal user + user: 'scan@domain.io', // generated ethereal user from: 'AElf scan ', to: ['test@mail.com'], - subject: 'error happened when scanning' + subject: 'error happened when scanning', + smtpConfig: { + host: "smtp.domain.com", + port: 465, + secure: true, + auth: { + user: "monitor@domain.com", + pass: "password", + } + } } }; diff --git a/package.json b/package.json index df6dce8..8422e2d 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "long": "^4.0.0", "moment": "^2.24.0", "mysql": "^2.17.1", - "nodemailer": "^6.3.0", + "nodemailer": "^6.8.0", "pm2": "^4.2.1", "redis": "^2.8.0" }, diff --git a/src/emails.js b/src/emails.js index 74e416f..5638971 100644 --- a/src/emails.js +++ b/src/emails.js @@ -11,17 +11,24 @@ const mailConfig = config.mails; async function sendEmails(message = '') { const { + type, from, to, subject, - sendmailPath + sendmailPath, + smtpConfig } = mailConfig; try { - const transporter = nodemailer.createTransport({ - sendmail: true, - newline: 'unix', - path: sendmailPath - }); + let transporter; + if (type === 'smtp') { + transporter = nodemailer.createTransport(smtpConfig); + } else { + transporter = nodemailer.createTransport({ + sendmail: true, + newline: 'unix', + path: sendmailPath + }); + } // send mail with defined transport object const info = await transporter.sendMail({