You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.3 KiB
41 lines
1.3 KiB
const Promise = require('bluebird'); |
|
const sendmail = Promise.promisify(require('sendmail')()); |
|
const { DM } = require('waliyun'); |
|
|
|
let doSendEmail; |
|
|
|
if (syzoj.config.email.method === "sendmail") { |
|
doSendEmail = async function send_sendmail(to, subject, body) { |
|
await sendmail({ |
|
from: `${syzoj.config.title} <${syzoj.config.email.options.address}>`, |
|
to: to, |
|
type: 'text/html', |
|
subject: subject, |
|
html: body |
|
}); |
|
} |
|
} else if (syzoj.config.email.method === "aliyundm") { |
|
const dm = DM({ |
|
AccessKeyId: syzoj.config.email.options.AccessKeyId, |
|
AccessKeySecret: syzoj.config.email.options.AccessKeySecret |
|
}); |
|
doSendEmail = async function send_aliyundm(to, subject, body) { |
|
const result = await dm.singleSendMail({ |
|
AccountName: syzoj.config.email.options.AccountName, |
|
AddressType: 1, |
|
ReplyToAddress: false, |
|
ToAddress: to, |
|
FromAlias: syzoj.config.title, |
|
Subject: subject, |
|
HtmlBody: body |
|
}); |
|
if (result.Code != null) { |
|
throw new Error("阿里云 API 错误:" + JSON.stringify(result)); |
|
} |
|
} |
|
} else { |
|
doSendEmail = async () => { |
|
throw new Error("邮件发送配置不正确。"); |
|
} |
|
} |
|
module.exports.send = doSendEmail; |