if smtp or sms config is empty, return immediately

This commit is contained in:
luk 2024-08-03 14:22:03 +08:00
parent 5fd32c86b3
commit 7b200e283a

View File

@ -13,6 +13,10 @@ module.exports = {
// 或者如果smtp参数已经确定就可以直接定义 sendMail: Bluebird.promisify(Smtp.sendMail).bind(Smtp)
async sendMail (messageObject, smtp = my.envar?.SMTP || wo?.envar?.SMTP) {
if (!smtp?.host) {
console.error({ _at: new Date().toJSON(), _state: 'SMTP_CONFIG_MALFORMED' }, '\n,')
return { _state: 'SMTP_CONFIG_MALFORMED' }
}
// messageObject: { from, to, cc, bcc, subject, text, html, sender, replyTo, inReplyTo }
sender.smtpTransporter = sender.smtpTransporter || NodeMailer.createTransport(smtp)
return await sender.smtpTransporter
@ -38,7 +42,7 @@ module.exports = {
return { _state: 'MSG_SEND_FAIL' }
})
.catch((error) => {
console.log({ _at: new Date().toJSON(), _state: 'SMS_SEND_ERROR', error }, '\n,')
console.error({ _at: new Date().toJSON(), _state: 'SMS_SEND_ERROR', error }, '\n,')
return { _state: 'SMS_SEND_ERROR' }
})
},
@ -54,7 +58,10 @@ module.exports = {
appid, // for 'UNICLOUD', 'TENCENT'
} = {}) {
if (/^\+\d+-\d+$/.test(phone)) {
if (config.vendor === 'DXTON') {
if (!config?.vendor) {
console.error({ _at: new Date().toJSON(), _state: 'SMS_CONFIG_MALFORMED' }, '\n,')
return { _state: 'SMS_CONFIG_MALFORMED' }
} else if (config.vendor === 'DXTON') {
return await this.sendSmsDxton({ phone, config, msg })
} else if (config.vendor === 'ALIYUN') {
return await this.sendSmsAliyun({ phone, config, msgParam, msgTemplate, signName })