mirror of
https://github.com/certd/certd.git
synced 2026-04-24 20:57:26 +08:00
chore: 模版发邮件 plus
This commit is contained in:
@@ -78,7 +78,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="border border-gray-300 px-4 py-2">
|
<td class="border border-gray-300 px-4 py-2">
|
||||||
<AddonSelector v-model:model-value="item.addonId" addon-type="emailTemplate" from="sys" :type="item.name" :placeholder="t('certd.sys.setting.email.templateProviderSelectorPlaceholder')" />
|
<AddonSelector
|
||||||
|
v-model:model-value="item.addonId"
|
||||||
|
:disabled="!settingStore.isPlus"
|
||||||
|
addon-type="emailTemplate"
|
||||||
|
from="sys"
|
||||||
|
:type="item.name"
|
||||||
|
:placeholder="t('certd.sys.setting.email.templateProviderSelectorPlaceholder')"
|
||||||
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -117,8 +117,8 @@ export class EmailService implements IEmailService {
|
|||||||
|
|
||||||
async test(userId: number, receiver: string) {
|
async test(userId: number, receiver: string) {
|
||||||
await this.sendByTemplate({
|
await this.sendByTemplate({
|
||||||
type:"common",
|
type: "common",
|
||||||
data:{
|
data: {
|
||||||
title: '测试邮件,from certd',
|
title: '测试邮件,from certd',
|
||||||
content: '测试邮件,from certd',
|
content: '测试邮件,from certd',
|
||||||
},
|
},
|
||||||
@@ -150,36 +150,39 @@ export class EmailService implements IEmailService {
|
|||||||
|
|
||||||
|
|
||||||
async sendByTemplate(req: EmailSendByTemplateReq) {
|
async sendByTemplate(req: EmailSendByTemplateReq) {
|
||||||
const emailConf = await this.sysSettingsService.getSetting<SysEmailConf>(SysEmailConf);
|
|
||||||
|
|
||||||
const template = emailConf?.templates?.[req.type]
|
|
||||||
let content = null
|
let content = null
|
||||||
if (template && template.addonId) {
|
if (isPlus()) {
|
||||||
const addon: ITemplateProvider<EmailContent> = await this.addonGetterService.getAddonById(template.addonId, true, 0)
|
const emailConf = await this.sysSettingsService.getSetting<SysEmailConf>(SysEmailConf);
|
||||||
if (addon) {
|
const template = emailConf?.templates?.[req.type]
|
||||||
content = await addon.buildContent({ data: req.data })
|
if (template && template.addonId) {
|
||||||
}
|
const addon: ITemplateProvider<EmailContent> = await this.addonGetterService.getAddonById(template.addonId, true, 0)
|
||||||
}
|
|
||||||
if (!content) {
|
|
||||||
//看看有没有通用模版
|
|
||||||
if (emailConf?.templates?.common && emailConf?.templates?.common.addonId) {
|
|
||||||
const addon: ITemplateProvider<EmailContent> = await this.addonGetterService.getAddonById(emailConf.templates.common.addonId, true, 0)
|
|
||||||
if (addon) {
|
if (addon) {
|
||||||
content = await addon.buildContent({ data: req.data })
|
content = await addon.buildContent({ data: req.data })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (!content) {
|
||||||
// 没有找到模版,使用默认模版
|
//看看有没有通用模版
|
||||||
if (!content) {
|
if (emailConf?.templates?.common && emailConf?.templates?.common.addonId) {
|
||||||
try {
|
const addon: ITemplateProvider<EmailContent> = await this.addonGetterService.getAddonById(emailConf.templates.common.addonId, true, 0)
|
||||||
const addon: ITemplateProvider<EmailContent> = await this.addonGetterService.getBlank("emailTemplate", req.type)
|
if (addon) {
|
||||||
content = await addon.buildDefaultContent({ data: req.data })
|
content = await addon.buildContent({ data: req.data })
|
||||||
} catch (e) {
|
}
|
||||||
// 对应的通知类型模版可能没有注册或者开发
|
}
|
||||||
const addon: ITemplateProvider<EmailContent> = await this.addonGetterService.getBlank("emailTemplate", "common")
|
|
||||||
content = await addon.buildDefaultContent({ data: req.data })
|
|
||||||
//common类型的一定有,已经开发了
|
|
||||||
}
|
}
|
||||||
|
// 没有找到模版,使用默认模版
|
||||||
|
if (!content) {
|
||||||
|
try {
|
||||||
|
const addon: ITemplateProvider<EmailContent> = await this.addonGetterService.getBlank("emailTemplate", req.type)
|
||||||
|
content = await addon.buildDefaultContent({ data: req.data })
|
||||||
|
} catch (e) {
|
||||||
|
// 对应的通知类型模版可能没有注册或者开发
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!content) {
|
||||||
|
const addon: ITemplateProvider<EmailContent> = await this.addonGetterService.getBlank("emailTemplate", "common")
|
||||||
|
content = await addon.buildDefaultContent({ data: req.data })
|
||||||
}
|
}
|
||||||
return await this.send({
|
return await this.send({
|
||||||
...req.email,
|
...req.email,
|
||||||
|
|||||||
Reference in New Issue
Block a user