const _ = require('lodash'); const assert = require('assert'); const { BusinessError, ErrorCode } = require('naf-core').Error; /** * 绑定邮箱模板 * @param {Object} sender 发送人设置 * @param {String} receiver 发送对象 * @param {Object} params 模板参数 * @prop {String} params.code 验证码 */ module.exports = (sender, receiver, params) => { assert(sender, '缺少发送人信息'); const { from, user, pass } = sender; const code = _.get(params, 'code'); if (!code) throw new BusinessError(ErrorCode.DATA_INVALID, '缺少模板需要的参数'); const text = `【邮箱绑定】验证码为:${code},用于平台用户信息验证,若非本人操作,请忽略此信息。<${from}>`; const auth = { user, pass }; const mailContext = { from: `"${from}" <${user}>`, // 邮件来源 to: receiver, // 邮件发送到哪里,多个邮箱使用逗号隔开 subject: `${from}-邮箱绑定`, // 邮件主题 html: text, // html类型的邮件正文 }; const mailConfig = { host: 'smtp.163.com', port: 465, secure: true, auth, }; return { mailContext, mailConfig }; };