mirror of
https://github.com/certd/certd.git
synced 2026-04-24 04:17:25 +08:00
fix: 发送证书到邮箱插件的邮件模版转为使用邮箱配置中的通用模版
This commit is contained in:
@@ -9,7 +9,8 @@ export type EmailSend = {
|
|||||||
export type EmailSendByTemplateReq = {
|
export type EmailSendByTemplateReq = {
|
||||||
type: string;
|
type: string;
|
||||||
data: any;
|
data: any;
|
||||||
email: { receivers: string[]; attachments?: any[] };
|
receivers: string[];
|
||||||
|
attachments?: any[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface IEmailService {
|
export interface IEmailService {
|
||||||
|
|||||||
@@ -108,9 +108,7 @@ export class CodeService {
|
|||||||
await this.emailService.sendByTemplate({
|
await this.emailService.sendByTemplate({
|
||||||
type: templateData.notificationType,
|
type: templateData.notificationType,
|
||||||
data: templateData,
|
data: templateData,
|
||||||
email:{
|
receivers: [email],
|
||||||
receivers: [email],
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const key = this.buildEmailCodeKey(email,opts?.verificationType);
|
const key = this.buildEmailCodeKey(email,opts?.verificationType);
|
||||||
|
|||||||
@@ -123,9 +123,7 @@ export class EmailService implements IEmailService {
|
|||||||
content: '测试邮件,from certd',
|
content: '测试邮件,from certd',
|
||||||
url:"https://certd.handfree.work",
|
url:"https://certd.handfree.work",
|
||||||
},
|
},
|
||||||
email: {
|
receivers: [receiver],
|
||||||
receivers: [receiver],
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,8 +184,9 @@ export class EmailService implements IEmailService {
|
|||||||
content = await addon.buildDefaultContent({ data: req.data })
|
content = await addon.buildDefaultContent({ data: req.data })
|
||||||
}
|
}
|
||||||
return await this.send({
|
return await this.send({
|
||||||
...req.email,
|
...content,
|
||||||
...content
|
receivers: req.receivers,
|
||||||
|
attachments: req.attachments,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export class EmailNotification extends BaseNotification {
|
|||||||
await this.ctx.emailService.sendByTemplate({
|
await this.ctx.emailService.sendByTemplate({
|
||||||
type: body.notificationType,
|
type: body.notificationType,
|
||||||
data: templateData,
|
data: templateData,
|
||||||
email: emailSend
|
...emailSend
|
||||||
})
|
})
|
||||||
|
|
||||||
// await this.ctx.emailService.send({
|
// await this.ctx.emailService.send({
|
||||||
|
|||||||
+52
-61
@@ -1,5 +1,5 @@
|
|||||||
import {AbstractTaskPlugin, FileItem, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput} from '@certd/pipeline';
|
import { AbstractTaskPlugin, FileItem, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from '@certd/pipeline';
|
||||||
import {CertInfo, CertReader} from "@certd/plugin-cert";
|
import { CertInfo, CertReader } from "@certd/plugin-cert";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { get } from 'lodash-es';
|
import { get } from 'lodash-es';
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ import { get } from 'lodash-es';
|
|||||||
icon: 'ion:mail-outline',
|
icon: 'ion:mail-outline',
|
||||||
desc: '通过邮件发送证书',
|
desc: '通过邮件发送证书',
|
||||||
group: pluginGroups.other.key,
|
group: pluginGroups.other.key,
|
||||||
showRunStrategy:false,
|
showRunStrategy: false,
|
||||||
default: {
|
default: {
|
||||||
strategy: {
|
strategy: {
|
||||||
runStrategy: RunStrategy.SkipWhenSucceed,
|
runStrategy: RunStrategy.SkipWhenSucceed,
|
||||||
@@ -45,7 +45,7 @@ export class DeployCertToMailPlugin extends AbstractTaskPlugin {
|
|||||||
component: {
|
component: {
|
||||||
name: 'EmailSelector',
|
name: 'EmailSelector',
|
||||||
vModel: 'value',
|
vModel: 'value',
|
||||||
mode:"tags",
|
mode: "tags",
|
||||||
},
|
},
|
||||||
required: true,
|
required: true,
|
||||||
})
|
})
|
||||||
@@ -78,40 +78,40 @@ export class DeployCertToMailPlugin extends AbstractTaskPlugin {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@TaskInput({
|
// @TaskInput({
|
||||||
title: '邮件标题',
|
// title: '邮件标题',
|
||||||
component: {
|
// component: {
|
||||||
name: 'a-input',
|
// name: 'a-input',
|
||||||
vModel: 'value',
|
// vModel: 'value',
|
||||||
placeholder:`证书申请成功【$\{mainDomain}】`,
|
// placeholder: `证书申请成功【$\{mainDomain}】`,
|
||||||
},
|
// },
|
||||||
helper: '请输入邮件标题否则将使用默认标题\n模板变量:主域名=$\{mainDomain}、全部域名=$\{domains}、过期时间=$\{expiresTime}、备注=$\{remark}、证书PEM=$\{crt}、证书私钥=$\{key}、中间证书/CA证书=$\{ic}',
|
// helper: '请输入邮件标题否则将使用默认标题\n模板变量:主域名=$\{mainDomain}、全部域名=$\{domains}、过期时间=$\{expiresTime}、备注=$\{remark}、证书PEM=$\{crt}、证书私钥=$\{key}、中间证书/CA证书=$\{ic}',
|
||||||
required: false,
|
// required: false,
|
||||||
})
|
// })
|
||||||
title!: string;
|
// title!: string;
|
||||||
|
|
||||||
@TaskInput({
|
// @TaskInput({
|
||||||
title: '邮件模版',
|
// title: '邮件模版',
|
||||||
component: {
|
// component: {
|
||||||
name: 'a-textarea',
|
// name: 'a-textarea',
|
||||||
vModel: 'value',
|
// vModel: 'value',
|
||||||
autosize: {
|
// autosize: {
|
||||||
minRows: 6,
|
// minRows: 6,
|
||||||
maxRows: 10,
|
// maxRows: 10,
|
||||||
},
|
// },
|
||||||
placeholder: `
|
// placeholder: `
|
||||||
<div>
|
// <div>
|
||||||
<p>证书申请成功</p>
|
// <p>证书申请成功</p>
|
||||||
<p>域名:$\{domains}</p>
|
// <p>域名:$\{domains}</p>
|
||||||
<p>证书有效期:$\{expiresTime}</p>
|
// <p>证书有效期:$\{expiresTime}</p>
|
||||||
<p>备注:$\{remark}</p>
|
// <p>备注:$\{remark}</p>
|
||||||
</div>
|
// </div>
|
||||||
`,
|
// `,
|
||||||
},
|
// },
|
||||||
helper: `请输入模版内容否则将使用默认模版,模板变量同上`,
|
// helper: `请输入模版内容否则将使用默认模版,模板变量同上`,
|
||||||
required: false,
|
// required: false,
|
||||||
})
|
// })
|
||||||
template!: string;
|
// template!: string;
|
||||||
|
|
||||||
@TaskInput({
|
@TaskInput({
|
||||||
title: '备注',
|
title: '备注',
|
||||||
@@ -123,7 +123,7 @@ export class DeployCertToMailPlugin extends AbstractTaskPlugin {
|
|||||||
})
|
})
|
||||||
remark!: string;
|
remark!: string;
|
||||||
|
|
||||||
async onInstance() {}
|
async onInstance() { }
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
|
|
||||||
this.logger.info(`开始发送邮件`);
|
this.logger.info(`开始发送邮件`);
|
||||||
@@ -132,41 +132,32 @@ export class DeployCertToMailPlugin extends AbstractTaskPlugin {
|
|||||||
const domains = certReader.getAllDomains().join(',');
|
const domains = certReader.getAllDomains().join(',');
|
||||||
|
|
||||||
|
|
||||||
const data = {
|
const data: any = {
|
||||||
mainDomain,
|
mainDomain,
|
||||||
domains,
|
domains,
|
||||||
expiresTime: dayjs(certReader.expires).format("YYYY-MM-DD HH:mm:ss"),
|
expiresTime: dayjs(certReader.expires).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
remark:this.remark ||"",
|
remark: this.remark || "",
|
||||||
crt: this.cert.crt,
|
crt: this.cert.crt,
|
||||||
key: this.cert.key,
|
key: this.cert.key,
|
||||||
ic: this.cert.ic
|
ic: this.cert.ic,
|
||||||
|
url: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
let title = `证书申请成功【${mainDomain}】`;
|
let title = `证书申请成功【${mainDomain}】`;
|
||||||
let html = `
|
let content = `证书申请成功
|
||||||
<div>
|
域名:${domains}
|
||||||
<p>证书申请成功</p>
|
证书有效期:${data.expiresTime}
|
||||||
<p>域名:${domains}</p>
|
备注:${this.remark || ""}
|
||||||
<p>证书有效期:${data.expiresTime}</p>
|
|
||||||
<p>备注:${this.remark||""}</p>
|
|
||||||
</div>
|
|
||||||
`;
|
`;
|
||||||
|
data.content = content;
|
||||||
if (this.title) {
|
data.title = title
|
||||||
const compile = this.compile(this.title);
|
|
||||||
title = compile(data);
|
|
||||||
}
|
|
||||||
if (this.template) {
|
|
||||||
const compile = this.compile(this.template);
|
|
||||||
html = compile(data);
|
|
||||||
}
|
|
||||||
const file = this.certZip
|
const file = this.certZip
|
||||||
if (!file) {
|
if (!file) {
|
||||||
throw new Error('证书压缩文件还未生成,重新运行证书任务');
|
throw new Error('证书压缩文件还未生成,重新运行证书任务');
|
||||||
}
|
}
|
||||||
await this.ctx.emailService.send({
|
await this.ctx.emailService.sendByTemplate({
|
||||||
subject:title,
|
type: "common",
|
||||||
html: html,
|
data,
|
||||||
receivers: this.email,
|
receivers: this.email,
|
||||||
attachments: [
|
attachments: [
|
||||||
{
|
{
|
||||||
@@ -178,7 +169,7 @@ export class DeployCertToMailPlugin extends AbstractTaskPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
compile(templateString: string) {
|
compile(templateString: string) {
|
||||||
return function(data) {
|
return function (data) {
|
||||||
return templateString.replace(/\${(.*?)}/g, (match, key) => {
|
return templateString.replace(/\${(.*?)}/g, (match, key) => {
|
||||||
const value = get(data, key, '');
|
const value = get(data, key, '');
|
||||||
return String(value);
|
return String(value);
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export class CommonEmailTemplateProvider extends BaseEmailTemplateProvider imple
|
|||||||
async buildDefaultContent(req:BuildContentReq) {
|
async buildDefaultContent(req:BuildContentReq) {
|
||||||
const defaultTemplate = new CommonEmailTemplateProvider()
|
const defaultTemplate = new CommonEmailTemplateProvider()
|
||||||
defaultTemplate.titleTemplate = "${title}"
|
defaultTemplate.titleTemplate = "${title}"
|
||||||
defaultTemplate.contentTemplate = "${content} \n\n 查看详情:${url}"
|
defaultTemplate.contentTemplate = "${content} \n\n ${url?'查看详情:'+url:''}"
|
||||||
defaultTemplate.formatType = "text"
|
defaultTemplate.formatType = "text"
|
||||||
return await defaultTemplate.buildContent(req)
|
return await defaultTemplate.buildContent(req)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user