Commit 2cef1dea by 胡悦

添加发送邮件功能

1 parent 711c221e
...@@ -11,3 +11,8 @@ SOCKET_PORT= 8080 ...@@ -11,3 +11,8 @@ SOCKET_PORT= 8080
APP_PORT= 3000 APP_PORT= 3000
STATIC_PATH = "public" STATIC_PATH = "public"
JWT_SECRET = 'secretKey' JWT_SECRET = 'secretKey'
SMTP_HOST='smtphz.qiye.163.com'
SMTP_PORT='465'
SMTP_USER='qianduan01@didihu.com.cn'
SMTP_PASSWORD='Q9gr7VKwJEr73d8F'
SMTP_FROM='qianduan01@didihu.com.cn'
\ No newline at end of file \ No newline at end of file
This diff could not be displayed because it is too large.
...@@ -32,11 +32,13 @@ ...@@ -32,11 +32,13 @@
"db": "rimraf ./src/modules/entities & typeorm-model-generator -h 192.168.3.113 -d app_admin -p 3306 -u user_limin -x LmotGSOY -e mysql -o ./src/modules/entities --noConfig true --ce pascal --cp camel" "db": "rimraf ./src/modules/entities & typeorm-model-generator -h 192.168.3.113 -d app_admin -p 3306 -u user_limin -x LmotGSOY -e mysql -o ./src/modules/entities --noConfig true --ce pascal --cp camel"
}, },
"dependencies": { "dependencies": {
"@css-inline/css-inline-darwin-arm64": "^0.14.3",
"@nest-modules/mailer": "^1.3.22", "@nest-modules/mailer": "^1.3.22",
"@nestjs-modules/mailer": "^1.6.0", "@nestjs-modules/mailer": "^1.11.2",
"@nestjs/axios": "^3.0.3", "@nestjs/axios": "^3.0.3",
"@nestjs/bull": "^0.1.1", "@nestjs/bull": "^0.1.1",
"@nestjs/common": "^10.4.1", "@nestjs/common": "^10.4.1",
"@nestjs/config": "^4.0.2",
"@nestjs/core": "^10.4.1", "@nestjs/core": "^10.4.1",
"@nestjs/event-emitter": "^2.0.4", "@nestjs/event-emitter": "^2.0.4",
"@nestjs/jwt": "^10.2.0", "@nestjs/jwt": "^10.2.0",
...@@ -57,13 +59,14 @@ ...@@ -57,13 +59,14 @@
"class-validator": "^0.12.2", "class-validator": "^0.12.2",
"compressing": "^1.5.1", "compressing": "^1.5.1",
"dayjs": "^1.11.13", "dayjs": "^1.11.13",
"ejs": "^3.1.10",
"global": "^4.4.0", "global": "^4.4.0",
"mysql": "^2.18.1", "mysql": "^2.18.1",
"nest-status-monitor": "^0.1.3", "nest-status-monitor": "^0.1.3",
"nest-winston": "^1.9.7", "nest-winston": "^1.9.7",
"nestjs-config": "^1.4.6", "nestjs-config": "^1.4.6",
"nestjs-prisma": "^0.23.0", "nestjs-prisma": "^0.23.0",
"nodemailer": "^6.4.16", "nodemailer": "^6.10.1",
"passport": "^0.4.1", "passport": "^0.4.1",
"passport-jwt": "^4.0.0", "passport-jwt": "^4.0.0",
"passport-local": "^1.0.0", "passport-local": "^1.0.0",
......
...@@ -2,7 +2,7 @@ import { resolve } from 'path' ...@@ -2,7 +2,7 @@ import { resolve } from 'path'
import { Module, MiddlewareConsumer, RequestMethod } from '@nestjs/common' import { Module, MiddlewareConsumer, RequestMethod } from '@nestjs/common'
import { ScheduleModule } from '@nestjs/schedule' import { ScheduleModule } from '@nestjs/schedule'
import { ConfigModule, ConfigService } from 'nestjs-config' import { ConfigModule, ConfigService } from 'nestjs-config'
// import { MailerModule } from '@nest-modules/mailer' import { MailerModule } from '@nest-modules/mailer'
// import { StatusMonitorModule } from 'nest-status-monitor' // import { StatusMonitorModule } from 'nest-status-monitor'
// import statusMonitorConfig from './config/statusMonitor' // import statusMonitorConfig from './config/statusMonitor'
import { LoggerMiddleware } from './common/middleware/logger.middleware' import { LoggerMiddleware } from './common/middleware/logger.middleware'
...@@ -21,6 +21,7 @@ import { WsModule } from './modules/ws/ws.module' ...@@ -21,6 +21,7 @@ import { WsModule } from './modules/ws/ws.module'
import { BroadcastModule } from './modules/broadcast/broadcast.module' import { BroadcastModule } from './modules/broadcast/broadcast.module'
import { ClueModule } from './modules/clue/clue.module'; import { ClueModule } from './modules/clue/clue.module';
import { DialogueModule } from './modules/dialogue/dialogue.module'; import { DialogueModule } from './modules/dialogue/dialogue.module';
import {EmailModule} from './email/email.module'
import { EventEmitterModule } from '@nestjs/event-emitter' import { EventEmitterModule } from '@nestjs/event-emitter'
import { HttpModule } from '@nestjs/axios' import { HttpModule } from '@nestjs/axios'
// import { FieldsModule } from './modules/fields/fields.module' // import { FieldsModule } from './modules/fields/fields.module'
...@@ -59,7 +60,8 @@ import winstonLogger from './initor/winstion.config' ...@@ -59,7 +60,8 @@ import winstonLogger from './initor/winstion.config'
BroadcastModule, BroadcastModule,
// FieldsModule, // FieldsModule,
ClueModule, ClueModule,
DialogueModule DialogueModule,
EmailModule
] ]
}) })
export class AppModule { export class AppModule {
......
import { ApiProperty } from '@nestjs/swagger'
// import { IsDateString, IsOptional } from 'class-validator';
export class EmailQueryDto {
@ApiProperty({
type: String,
description: '收件人',
required: true
})
to?: string;
@ApiProperty({
type: String,
description: '标题',
required: true
})
subject?: string;
}
\ No newline at end of file \ No newline at end of file
import { Controller, Get, Query, Render } from '@nestjs/common';
import { EmailService } from './email.service';
import { EmailQueryDto } from 'src/dto/email.dto';
@Controller('email')
export class EmailController {
constructor(private readonly emailService: EmailService) {}
@Get('send')
async sendEmail(@Query() query: EmailQueryDto) {
const {to, subject} = query
try {
await this.emailService.sendMail(to, subject);
return 'Email sent successfully!';
} catch (error) {
return 'Email sending failed: ' + error;
}
}
}
\ No newline at end of file \ No newline at end of file
// mail/mail.module.ts
import { Module } from '@nestjs/common';
import { MailerModule } from '@nestjs-modules/mailer';
import { EjsAdapter } from '@nestjs-modules/mailer/dist/adapters/ejs.adapter';
import { EmailService } from './email.service';
import { EmailController } from './email.controller';
const path = require('path')
@Module({
imports: [
MailerModule.forRoot({
transport: {
host: process.env.SMTP_HOST,
port: +process.env.SMTP_PORT,
secure: true, // true for 465, false for other ports
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASSWORD,
},
},
preview: true,
defaults: {
from: `"Your App" <${process.env.SMTP_FROM}>`,
},
template: {
dir: path.join(process.cwd(), './src/email/templates'),
adapter: new EjsAdapter(),
options: {
strict: true,
},
},
}),
],
controllers: [EmailController], // 注册控制器
providers: [EmailService],
exports: [EmailService], // 导出服务以便其他模块使用
})
export class EmailModule {}
\ No newline at end of file \ No newline at end of file
// mail/mail.service.ts
import { Injectable } from '@nestjs/common';
import { MailerService } from '@nestjs-modules/mailer';
import * as nodemailer from 'nodemailer';
@Injectable()
export class EmailService {
// private transporter;
constructor(private readonly mailerService: MailerService) {}
// constructor() {
// this.transporter = nodemailer.createTransport({
// host: process.env.SMTP_HOST,
// port: +process.env.SMTP_PORT,
// secure: true, // 如果是 SMTPS 连接,设置为 true
// auth: {
// user: process.env.SMTP_USER,
// pass: process.env.SMTP_PASSWORD,
// },
// });
// }
async sendMail(to: string, subject: string): Promise<void> {
// 模拟数据
const weeklyData = [
{
date: '5.20 - 5.26',
totalPeople: 11,
validClicks: 2,
clickCount: 2,
activeItems: 8,
createdTasks: 1,
peakDay: '5.21、5.23 / 1',
highlight: true
},
];
const reportData = [
{
title: '区域运营考核模版',
content: '用于提交督导当天店面的业绩、招聘、培训、客户接待和工作小结情况。',
discript: '每日提交份数(与店面上班人数有关) / 填报人数(所有关联该模版的员工数,包括当天请假或者休息的员工)(数据如下①)',
time: '2025/1/21'
},
{
title: '督导培训日报模版',
content: '用于提交督导给新员工培训记录(通过腾讯会议进行培训,然后填写该模版,模版内容包括培训类型、主题、人员、形式、腾讯会议连接、照片)。',
discript: '5.6-5.11,有 0 份提交记录。 / 填报人数(所有关联该模版的员工数,包括当天请假或者休息的员工)(数据如下①)',
time: '2025/2025/04/16/21'
}
]
const assessmentList = [
{
date: '5.20(周二)',
submit: 14,
fill: 21,
submitRate: '66.7'
},
{
date: '5.20(周二)',
submit: 14,
fill: 21,
submitRate: '66.7'
},
{
date: '5.20(周二)',
submit: 14,
fill: 21,
submitRate: ''
},
{
date: '5.20(周二)',
submit: 14,
fill: 21,
submitRate: ''
}
]
const mailOptions = {
from: process.env.SMTP_FROM,
to,
subject,
template: './function.point.ejs',
context: {
code: 1, //验证码
date: '2025-05-28', //日期
sign: '系统邮件,回复无效。', //发送的签名,当然也可以不要
weeklyData,
reportData,
assessmentList
}
};
await this.mailerService.sendMail(mailOptions);
}
}
\ No newline at end of file \ No newline at end of file
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>数据统计表格</title>
<style>
table {
border-collapse: collapse;
width: 100%;
max-width: 1200px;
margin: 20px auto;
}
th,
td {
border: 1px solid #ddd;
padding: 10px 15px;
text-align: center;
}
th {
font-weight: bold;
}
tr.highlight {
background-color: #e8f5e9;
}
.last-bg td:last-child {
background-color: #f1f4fe;
}
.last-bg tr td:last-child {
background-color: #f1f4fe;
}
</style>
</head>
<body>
<div>
<p>各位领导、同事:</p>
<p style="text-indent: 2em;">以下是重点功能上线后的使用情况,邮件中仅展示 5/20-5/26 的数据。</p>
<p style="text-indent: 2em;">所有的数据汇总文档:<a
href="https://mcnywc2tcye7.feishu.cn/wiki/IOxow8gSUijONfkntpVcp7Wbnph">所有数据汇总在线文档</a></p>
<h3>1、<span style="text-decoration: underline;">带教管理&填写带教任务&飞行督导工作日报&群推送</span></h3>
<h4>带教管理 上线时间(4.16)小程序(入口埋点)</h4>
<table>
<thead>
<tr>
<th>日期</th>
<th>总数(人)</th>
<th>有效点击人员数(人)</th>
<th>点击量(次)</th>
<th>进行中的带教条数(条)</th>
<th>创建任务(条)</th>
<th>最高点击日 / 次数(原因)</th>
</tr>
</thead>
<tbody>
<% locals.weeklyData.forEach(row=> { %>
<tr class="highlight">
<td>
<%= row.date %>
</td>
<td>
<%= row.totalPeople %>
</td>
<td>
<%= row.validClicks %>
</td>
<td>
<%= row.clickCount %>
</td>
<td>
<%= row.activeItems %>
</td>
<td>
<%= row.createdTasks %>
</td>
<td>
<%= row.peakDay %>
</td>
</tr>
<% }); %>
</tbody>
</table>
<br />
<h4>工作日报(督导) 上线时间(4.16)小程序(入口埋点)</h4>
<table>
<thead>
<tr>
<th>日期</th>
<th>总数(人)</th>
<th>有效点击人员数(人)</th>
<th>点击量(次)</th>
<th>精品升级入口(次)</th>
<th>会员权益入口(次)</th>
</tr>
</thead>
<tbody>
<% locals.weeklyData.forEach(row=> { %>
<tr class="highlight">
<td>
<%= row.date %>
</td>
<td>
<%= row.totalPeople %>
</td>
<td>
<%= row.validClicks %>
</td>
<td>
<%= row.clickCount %>
</td>
<td>
<%= row.activeItems %>
</td>
<td>
<%= row.createdTasks %>
</td>
</tr>
<% }); %>
</tbody>
</table>
<br />
<p>pc数据分析如下:</p>
<p>目前,建了三种日报模版(区域运营考核模版,督导培训日报模版,导师培训日报模版)。</p>
<table>
<thead>
<tr>
<th></th>
<th>模版内容</th>
<th>填写情况</th>
<th>上线时间</th>
</tr>
</thead>
<tbody>
<% locals.reportData.forEach(row=> { %>
<tr>
<td>
<%= row.title %>
</td>
<td>
<%= row.content %>
</td>
<td>
<%= row.discript %>
</td>
<td>
<%= row.time %>
</td>
</tr>
<% }); %>
</tbody>
</table>
<br />
<p>① 区域运营考核模版数据计算</p>
<table>
<thead>
<tr>
<th>日期</th>
<th>每日提交份数</th>
<th>填报人数(所有关联该模版的督导人数,包括当天请假或者休息的员工)</th>
<th>提交率</th>
</tr>
</thead>
<tbody>
<% locals.assessmentList.forEach(row=> { %>
<tr class="highlight">
<td>
<%= row.date %>
</td>
<td>
<%= row.submit %>
</td>
<td>
<%= row.fill %>
</td>
<td>
<%= row.submitRate %>%
</td>
</tr>
<% }); %>
</tbody>
</table>
<p>导师模版 上线时间(4.16) - 目前,业务端没开始用</p>
<br />
<h3>2、<span style="text-decoration: underline;">话术萃取 上线时间(4.16)</span></h3>
<p>数据库统计(浏览时长得是 60s以上 才会记录)</p>
<table>
<thead>
<tr>
<th>日期</th>
<th>总浏览次数(次)①</th>
<th>总浏览人数(人)②</th>
<th>总浏览批次(次)③</th>
</tr>
</thead>
<tbody>
<% locals.assessmentList.forEach(row=> { %>
<tr class="highlight">
<td>
<%= row.date %>
</td>
<td>
<%= row.submit %>
</td>
<td>
<%= row.fill %>
</td>
<td>
<%= row.submitRate %>%
</td>
</tr>
<% }); %>
</tbody>
</table>
<p>① 总浏览次数:在时间周期内,所有话术的总浏览次数。</p>
<p>② 总浏览人次:在时间周期内,浏览话术的所有人次。</p>
<p>③ 总浏览批次:在时间周期内,批量浏览话术的总次数,即一次性批量浏览多条话术。</p>
<p>话术萃取推送已关闭(4月21停止推送 )</p>
<br />
<h3>3、<span style="text-decoration: underline;">营销素材 上线时间(3.12)</span></h3>
<p>数据库统计(点击素材浏览算一次点击)</p>
<table>
<thead>
<tr>
<th>日期</th>
<th>有效点击(次)</th>
<th>点击人数(人)</th>
<th>备注</th>
</tr>
</thead>
<tbody>
<% locals.assessmentList.forEach(row=> { %>
<tr class="highlight">
<td>
<%= row.date %>
</td>
<td>
<%= row.submit %>
</td>
<td>
<%= row.fill %>
</td>
<td>
<%= row.submitRate ? row.submitRate : '——' %>%
</td>
</tr>
<% }); %>
</tbody>
</table>
<br />
<h3>4、<span style="text-decoration: underline;">场景集市 上线时间(4.16)</span></h3>
<table>
<thead>
<tr>
<th>日期</th>
<th>有效点击(次)</th>
<th>点击人数(人)</th>
<th>备注</th>
</tr>
</thead>
<tbody>
<% locals.assessmentList.forEach(row=> { %>
<tr class="highlight">
<td>
<%= row.date %>
</td>
<td>
<%= row.submit %>
</td>
<td>
<%= row.fill %>
</td>
<td>
<%= row.submitRate ? row.submitRate : '——' %>%
</td>
</tr>
<% }); %>
</tbody>
</table>
<br />
<h3>5、<span style="text-decoration: underline;">培训资料</span></h3>
<table>
<thead>
<tr>
<th>日期</th>
<th>有效点击(次)</th>
<th>点击人数(人)</th>
<th>备注</th>
</tr>
</thead>
<tbody>
<% locals.assessmentList.forEach(row=> { %>
<tr class="highlight">
<td>
<%= row.date %>
</td>
<td>
<%= row.submit %>
</td>
<td>
<%= row.fill %>
</td>
<td>
<%= row.submitRate ? row.submitRate : '——' %>%
</td>
</tr>
<% }); %>
</tbody>
</table>
<br />
<h3>6、<span style="text-decoration: underline;">AI助手 上线时间(5.16)</span></h3>
<h4>智能体使用情况</h4>
<ul>
<li>1、表格中统计的数据为:提问人数(人)、提问次数(次)</li>
<li>2、表格中底色的用于标识当天提问最高人次、当天提问最高次数</li>
<li>3、表格中空白处代表 0人、0次</li>
</ul>
<table class="last-bg">
<thead>
<tr>
<th></th>
<th>总部管理制度</th>
<th>AI营销助理</th>
<th>众筹续保测算智能体</th>
<th>对接人查询</th>
<th>对接人查询 2</th>
<th>驻店管理制度(智能体)</th>
<th>汇总</th>
</tr>
</thead>
<tbody>
<% locals.assessmentList.forEach(row=> { %>
<tr>
<td>
<%= row.date %>
</td>
<td>
<%= row.submit %>
</td>
<td>
<%= row.fill %>
</td>
<td>
<%= row.submitRate ? row.submitRate : '' %>%
</td>
<td>
<%= row.submitRate ? row.submitRate : '' %>%
</td>
<td>
<%= row.submitRate ? row.submitRate : '' %>%
</td>
<td>
<%= row.submitRate ? row.submitRate : '' %>%
</td>
<td>
<%= row.submitRate ? row.submitRate : '' %>%
</td>
</tr>
<% }); %>
</tbody>
</table>
</div>
</body>
</html>
\ No newline at end of file \ No newline at end of file
<div class="biu-nav-email"
style="max-width: 600px;min-width: 300px;margin: 40px auto;box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.1);font-size: 16px;padding: 20px;background-image: linear-gradient(to right, #9646de 0%, #cb03e4 100%);border-radius: 5px;color: #fff;">
<h3 style="margin-bottom: 40px;">
Hi! 亲爱的用户:
</h3>
<p style="padding-left: 20px;">
您正在进行邮箱验证,本次请求的验证码为:
</p>
<p style="color: #dde2e2;padding-left: 14px;">
<strong style="color: #3acbff;font-size: 24px;">
<%= locals.code %>
</strong>
<span>(为了保障您帐号的安全性,请在30分钟内完成验证,祝您生活愉快!)</span>
</p>
<p style="padding-left: 20px;">
<span>快速访问:</span>
<a href="https://www.biunav.com" style="color:#fff" target="_blank"
rel="noopener noreferrer">https://www.biunav.com</a>
</p>
<p style="margin-top: 40px;text-align: right;">
<%= locals.sign %>
</p>
<p style="text-align: right;">
<%= locals.date %>
</p>
</div>
\ No newline at end of file \ No newline at end of file
...@@ -10,7 +10,8 @@ ...@@ -10,7 +10,8 @@
"outDir": "./dist", "outDir": "./dist",
"baseUrl": "./", "baseUrl": "./",
"incremental": true, "incremental": true,
"resolveJsonModule": true "resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
}, },
"exclude": ["node_modules", "dist"] "exclude": ["node_modules", "dist"]
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!