From 1c843fb1bf9bd1474418ee57559e9499d8a321bf Mon Sep 17 00:00:00 2001 From: lxy Date: Wed, 28 Aug 2024 12:19:29 +0800 Subject: [PATCH] utils/email --- src/utils/email/index.frontend.ts | 38 +++---------------------------- src/utils/email/index.server.ts | 31 ------------------------- src/utils/email/index.ts | 9 ++++---- 3 files changed, 7 insertions(+), 71 deletions(-) delete mode 100644 src/utils/email/index.server.ts diff --git a/src/utils/email/index.frontend.ts b/src/utils/email/index.frontend.ts index c892a9291..803046f0d 100644 --- a/src/utils/email/index.frontend.ts +++ b/src/utils/email/index.frontend.ts @@ -3,42 +3,10 @@ import { EntityDict } from '../../oak-app-domain'; import { BRC } from '../../types/RuntimeCxt'; import Email, { EmailOptions } from '../../types/Email'; -import Nodemailer from './node-mailer'; - -const EmailDict: Record = { - nodemailer: Nodemailer, -}; - -/** - * 注入一个其它发送邮件类 - * @param clazz - */ -export function registEmail(clazz: new () => Email) { - const instance = new clazz(); - EmailDict[instance.name] = instance; -} - -export function getEmail(origin: string) { - assert(EmailDict.hasOwnProperty(origin)); - return EmailDict[origin] as Email; -} - -export function getOrigin() { - return Object.keys(EmailDict); -} - export async function sendEmail( options: EmailOptions, context: BRC ) { - try { - const instance = getEmail('nodemailer'); - const result = await instance.sendEmail(options, context); - return result; - } catch (err) { - return { - success: false, - res: err, - }; - } -} + const { text, html } = options; + console.log('邮件内容:', html || text); +} \ No newline at end of file diff --git a/src/utils/email/index.server.ts b/src/utils/email/index.server.ts deleted file mode 100644 index de2fb5164..000000000 --- a/src/utils/email/index.server.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { assert } from 'oak-domain/lib/utils/assert'; -import { EntityDict } from '../../oak-app-domain'; -import { BRC } from '../../types/RuntimeCxt'; -import Email, { EmailOptions } from '../../types/Email'; - -const EmailDict: Record = {}; - -/** - * 注入一个其它发送邮件类 - * @param clazz - */ -export function registEmail(clazz: new () => Email) { - const instance = new clazz(); - EmailDict[instance.name] = instance; -} - -export function getEmail(origin: string) { - assert(EmailDict.hasOwnProperty(origin)); - return EmailDict[origin] as Email; -} - -export function getOrigin() { - return Object.keys(EmailDict); -} - -export async function sendEmail( - options: EmailOptions, - context: BRC -) { - console.log('前后模式下,前端无需发送邮件') -} diff --git a/src/utils/email/index.ts b/src/utils/email/index.ts index f78ca48d7..635f91c9c 100644 --- a/src/utils/email/index.ts +++ b/src/utils/email/index.ts @@ -5,7 +5,6 @@ import Email, { EmailOptions } from '../../types/Email'; import Nodemailer from './node-mailer'; -// 邮箱发送先直接注入nodemailer 后面要注入自己的邮件发送逻辑再说 by wkj const EmailDict: Record = { nodemailer: Nodemailer, }; @@ -14,7 +13,7 @@ const EmailDict: Record = { * 注入一个其它发送邮件类 * @param clazz */ -export function registEmail(clazz: new () => Email) { +export function registerEmail(clazz: new () => Email) { const instance = new clazz(); EmailDict[instance.name] = instance; } @@ -36,10 +35,10 @@ export async function sendEmail( const instance = getEmail('nodemailer'); const result = await instance.sendEmail(options, context); return result; - } catch (err: any) { + } catch (err) { return { success: false, - error: err?.message, + error: err, }; } -} +} \ No newline at end of file