Skip to content

Commit

Permalink
feat: 新增 email 推送支持
Browse files Browse the repository at this point in the history
  • Loading branch information
CaoMeiYouRen committed Feb 27, 2021
1 parent 51af58f commit 5fc9996
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@types/lodash": "^4.14.168",
"@types/module-alias": "^2.0.0",
"@types/node": "^14.14.31",
"@types/nodemailer": "^6.4.0",
"@types/qs": "^6.9.5",
"@typescript-eslint/eslint-plugin": "^4.15.2",
"@typescript-eslint/parser": "^4.15.2",
Expand Down Expand Up @@ -73,6 +74,7 @@
"colors": "^1.4.0",
"crypto-js": "^4.0.0",
"debug": "^4.3.1",
"nodemailer": "^6.5.0",
"qs": "^6.9.6"
},
"config": {
Expand Down
32 changes: 32 additions & 0 deletions src/push/email.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Send } from '../interfaces/send'
import { createTransport, SendMailOptions } from 'nodemailer'
import debug from 'debug'

const Debugger = debug('push:email')

type Mail = ReturnType<typeof createTransport>
type Args = Parameters<typeof createTransport>

export class Email implements Send {

private mail: Mail

constructor(...args: Args) {
this.mail = createTransport(...args)
}

close(): void {
this.mail.close()
}

async send(mailOptions: SendMailOptions): Promise<any> {
return new Promise((resolve: (value: unknown) => void, reject: (err: Error) => void) => {
this.mail.sendMail(mailOptions, (err, info) => {
if (err) {
return reject(err)
}
return resolve(info)
})
})
}
}
3 changes: 3 additions & 0 deletions src/push/server-chan-turbo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export class ServerChanTurbo implements Send {
constructor(SCTKEY: string) {
this.SCTKEY = SCTKEY
Debugger('set SCTKEY: "%s"', SCTKEY)
if (!this.SCTKEY) {
throw new Error('SCTKEY is required!')
}
}
/**
*
Expand Down
3 changes: 3 additions & 0 deletions src/push/server-chan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export class ServerChan implements Send {
*/
constructor(SCKEY: string) {
this.SCKEY = SCKEY
if (!this.SCKEY) {
throw new Error('SCKEY is required!')
}
}
/**
* 请前往 https://sc.ftqq.com 领取
Expand Down

0 comments on commit 5fc9996

Please sign in to comment.