mirror of https://github.com/certd/certd
chore: 官方email服务支持发送附件
parent
978fa54518
commit
53d276a8fc
|
|
@ -3,7 +3,7 @@ import { AppKey, PlusRequestService } from '@certd/plus-core';
|
||||||
import { cache, http, HttpRequestConfig, logger } from '@certd/basic';
|
import { cache, http, HttpRequestConfig, logger } from '@certd/basic';
|
||||||
import { SysInstallInfo, SysLicenseInfo, SysSettingsService } from '../../settings/index.js';
|
import { SysInstallInfo, SysLicenseInfo, SysSettingsService } from '../../settings/index.js';
|
||||||
import { merge } from 'lodash-es';
|
import { merge } from 'lodash-es';
|
||||||
|
import fs from 'fs';
|
||||||
@Provide("plusService")
|
@Provide("plusService")
|
||||||
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
||||||
export class PlusService {
|
export class PlusService {
|
||||||
|
|
@ -85,12 +85,31 @@ export class PlusService {
|
||||||
|
|
||||||
async sendEmail(email: any) {
|
async sendEmail(email: any) {
|
||||||
const plusRequestService = await this.getPlusRequestService();
|
const plusRequestService = await this.getPlusRequestService();
|
||||||
|
|
||||||
|
let attachments = email.attachments || [];
|
||||||
|
if (attachments.length > 0) {
|
||||||
|
const newAttachments: any[] = [];
|
||||||
|
attachments.forEach((item: any) => {
|
||||||
|
const name = item.filename || item.path.split('/').pop();
|
||||||
|
const body = item.content || fs.readFileSync(item.path);
|
||||||
|
const bodyBase64 = Buffer.from(body).toString('base64');
|
||||||
|
item = {
|
||||||
|
name,
|
||||||
|
body: bodyBase64,
|
||||||
|
};
|
||||||
|
newAttachments.push(item);
|
||||||
|
});
|
||||||
|
attachments = newAttachments;
|
||||||
|
}
|
||||||
|
|
||||||
await plusRequestService.request({
|
await plusRequestService.request({
|
||||||
url: '/activation/emailSend',
|
url: '/activation/emailSend',
|
||||||
data: {
|
data: {
|
||||||
subject: email.subject,
|
subject: email.subject,
|
||||||
text: email.content,
|
|
||||||
to: email.receivers,
|
to: email.receivers,
|
||||||
|
text: email.content,
|
||||||
|
html: email.html,
|
||||||
|
attachments,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,6 @@ export default ({ command, mode }) => {
|
||||||
// if (mode.startsWith("dev")) {
|
// if (mode.startsWith("dev")) {
|
||||||
// base = "./";
|
// base = "./";
|
||||||
// }
|
// }
|
||||||
let proxyTarget: string = "https://127.0.0.1:7002";
|
|
||||||
if (mode === "remote") {
|
|
||||||
proxyTarget = "https://yfy.docmirror.cn:7002";
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
base: base,
|
base: base,
|
||||||
plugins: [
|
plugins: [
|
||||||
|
|
@ -86,14 +82,14 @@ export default ({ command, mode }) => {
|
||||||
},
|
},
|
||||||
server: {
|
server: {
|
||||||
host: "0.0.0.0",
|
host: "0.0.0.0",
|
||||||
port: 13008,
|
port: 3008,
|
||||||
fs: devServerFs,
|
fs: devServerFs,
|
||||||
allowedHosts: ["localhost", "127.0.0.1", "yfy.docmirror.cn"],
|
allowedHosts: ["localhost", "127.0.0.1", "yfy.docmirror.cn"],
|
||||||
proxy: {
|
proxy: {
|
||||||
// with options
|
// with options
|
||||||
"/api": {
|
"/api": {
|
||||||
//配套后端 https://github.com/fast-crud/fs-server-js
|
//配套后端 https://github.com/fast-crud/fs-server-js
|
||||||
target: proxyTarget,
|
target: "https://127.0.0.1:7002",
|
||||||
//忽略证书
|
//忽略证书
|
||||||
agent: new https.Agent({ rejectUnauthorized: false }),
|
agent: new https.Agent({ rejectUnauthorized: false }),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue