新增邮件发送和管理员功能
This commit is contained in:
46
mail-worker/src/service/resend-service.js
Normal file
46
mail-worker/src/service/resend-service.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import emailService from './email-service';
|
||||
import { emailConst } from '../const/entity-const';
|
||||
import BizError from '../error/biz-error';
|
||||
|
||||
const resendService = {
|
||||
|
||||
async webhooks(c, body) {
|
||||
|
||||
const params = {}
|
||||
|
||||
if (body.type === 'email.delivered') {
|
||||
params.status = emailConst.status.DELIVERED
|
||||
params.resendEmailId = body.data.email_id
|
||||
params.message = null
|
||||
}
|
||||
|
||||
if (body.type === 'email.complained') {
|
||||
params.status = emailConst.status.COMPLAINED
|
||||
params.resendEmailId = body.data.email_id
|
||||
params.message = null
|
||||
}
|
||||
|
||||
if (body.type === 'email.bounced') {
|
||||
let bounce = body.data.bounce
|
||||
bounce = JSON.stringify(bounce);
|
||||
params.status = emailConst.status.BOUNCED
|
||||
params.resendEmailId = body.data.email_id
|
||||
params.message = bounce
|
||||
}
|
||||
|
||||
if (body.type === 'email.delivery_delayed') {
|
||||
params.status = emailConst.status.DELAYED
|
||||
params.resendEmailId = body.data.email_id
|
||||
params.message = null
|
||||
}
|
||||
|
||||
const emailRow = await emailService.updateEmailStatus(c, params)
|
||||
|
||||
if (!emailRow) {
|
||||
throw new BizError('更新邮件状态记录失败');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export default resendService
|
||||
Reference in New Issue
Block a user