email.service.ts
1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// mail/mail.service.ts
import { Injectable, Logger } from '@nestjs/common';
import { MailerService } from '@nestjs-modules/mailer';
import * as nodemailer from 'nodemailer';
import { EmailQueryDto } from 'src/dto/email.dto';
@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(query: EmailQueryDto): Promise<void> {
const { to, subject, mentorship_page, supervisor_daily_page, extraction, reportData, template, sales_content, training_materials, scene_market, aiAgentColumns, ai_agent } = query
Logger.log(aiAgentColumns, 'aiAgentColumns')
const mailOptions = {
from: process.env.SMTP_FROM,
to,
subject,
template: './function.point.ejs',
context: {
code: 1, //验证码
date: '2025-05-28', //日期
sign: '系统邮件,回复无效。', //发送的签名,当然也可以不要
mentorship_page,
supervisor_daily_page,
extraction,
sales_content,
training_materials,
scene_market,
reportData,
template,
aiAgentColumns,
ai_agent
// mentorship_page: mentorship_page,
// supervisor_daily_page: JSON.parse(supervisor_daily_page),
// extraction: JSON.parse(extraction),
// sales_content: JSON.parse(sales_content),
// training_materials: JSON.parse(training_materials),
// scene_market: JSON.parse(scene_market)
}
};
await this.mailerService.sendMail(mailOptions);
}
}