mirror of
https://github.com/certd/certd.git
synced 2026-04-24 20:57:26 +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({
|
||||||
|
|||||||
+45
-54
@@ -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: '备注',
|
||||||
@@ -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: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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