Merge branch 'main' of http://39.117.244.52:3000/kjs/ERP-node into feature/report

This commit is contained in:
dohyeons
2025-10-02 18:01:14 +09:00
183 changed files with 2927 additions and 1109 deletions

View File

@@ -178,14 +178,19 @@ export class MailAccountFileController {
try {
const { id } = req.params;
// TODO: 실제 SMTP 연결 테스트 구현
// const account = await mailAccountFileService.getAccountById(id);
// nodemailer로 연결 테스트
const account = await mailAccountFileService.getAccountById(id);
if (!account) {
return res.status(404).json({
success: false,
message: '계정을 찾을 수 없습니다.',
});
}
return res.json({
success: true,
message: '연결 테스트 성공 (미구현)',
});
// mailSendSimpleService의 testConnection 사용
const { mailSendSimpleService } = require('../services/mailSendSimpleService');
const result = await mailSendSimpleService.testConnection(id);
return res.json(result);
} catch (error: unknown) {
const err = error as Error;
return res.status(500).json({

View File

@@ -7,10 +7,12 @@ export class MailSendSimpleController {
*/
async sendMail(req: Request, res: Response) {
try {
console.log('📧 메일 발송 요청 수신:', { accountId: req.body.accountId, to: req.body.to, subject: req.body.subject });
const { accountId, templateId, to, subject, variables, customHtml } = req.body;
// 필수 파라미터 검증
if (!accountId || !to || !Array.isArray(to) || to.length === 0) {
console.log('❌ 필수 파라미터 누락');
return res.status(400).json({
success: false,
message: '계정 ID와 수신자 이메일이 필요합니다.',

View File

@@ -1,8 +1,12 @@
import { Router } from 'express';
import { mailAccountFileController } from '../controllers/mailAccountFileController';
import { authenticateToken } from '../middleware/authMiddleware';
const router = Router();
// 모든 메일 계정 라우트에 인증 미들웨어 적용
router.use(authenticateToken);
router.get('/', (req, res) => mailAccountFileController.getAllAccounts(req, res));
router.get('/:id', (req, res) => mailAccountFileController.getAccountById(req, res));
router.post('/', (req, res) => mailAccountFileController.createAccount(req, res));

View File

@@ -4,8 +4,12 @@
import express from 'express';
import { MailReceiveBasicController } from '../controllers/mailReceiveBasicController';
import { authenticateToken } from '../middleware/authMiddleware';
const router = express.Router();
// 모든 메일 수신 라우트에 인증 미들웨어 적용
router.use(authenticateToken);
const controller = new MailReceiveBasicController();
// 메일 목록 조회

View File

@@ -1,8 +1,12 @@
import { Router } from 'express';
import { mailSendSimpleController } from '../controllers/mailSendSimpleController';
import { authenticateToken } from '../middleware/authMiddleware';
const router = Router();
// 모든 메일 발송 라우트에 인증 미들웨어 적용
router.use(authenticateToken);
// POST /api/mail/send/simple - 메일 발송
router.post('/simple', (req, res) => mailSendSimpleController.sendMail(req, res));

View File

@@ -1,8 +1,12 @@
import { Router } from 'express';
import { mailTemplateFileController } from '../controllers/mailTemplateFileController';
import { authenticateToken } from '../middleware/authMiddleware';
const router = Router();
// 모든 메일 템플릿 라우트에 인증 미들웨어 적용
router.use(authenticateToken);
// 템플릿 CRUD
router.get('/', (req, res) => mailTemplateFileController.getAllTemplates(req, res));
router.get('/:id', (req, res) => mailTemplateFileController.getTemplateById(req, res));

View File

@@ -6,6 +6,7 @@
import nodemailer from 'nodemailer';
import { mailAccountFileService } from './mailAccountFileService';
import { mailTemplateFileService } from './mailTemplateFileService';
import { encryptionService } from './encryptionService';
export interface SendMailRequest {
accountId: string;
@@ -56,18 +57,39 @@ class MailSendSimpleService {
throw new Error('메일 내용이 없습니다.');
}
// 4. SMTP 연결 생성
// 4. 비밀번호 복호화
const decryptedPassword = encryptionService.decrypt(account.smtpPassword);
console.log('🔐 비밀번호 복호화 완료');
console.log('🔐 암호화된 비밀번호 (일부):', account.smtpPassword.substring(0, 30) + '...');
console.log('🔐 복호화된 비밀번호 길이:', decryptedPassword.length);
// 5. SMTP 연결 생성
// 포트 465는 SSL/TLS를 사용해야 함
const isSecure = account.smtpPort === 465 ? true : (account.smtpSecure || false);
console.log('📧 SMTP 연결 설정:', {
host: account.smtpHost,
port: account.smtpPort,
secure: isSecure,
user: account.smtpUsername,
});
const transporter = nodemailer.createTransport({
host: account.smtpHost,
port: account.smtpPort,
secure: account.smtpSecure, // SSL/TLS
secure: isSecure, // SSL/TLS (포트 465는 자동으로 true)
auth: {
user: account.smtpUsername,
pass: account.smtpPassword,
pass: decryptedPassword, // 복호화된 비밀번호 사용
},
// 타임아웃 설정 (30초)
connectionTimeout: 30000,
greetingTimeout: 30000,
});
// 5. 메일 발송
console.log('📧 메일 발송 시도 중...');
// 6. 메일 발송
const info = await transporter.sendMail({
from: `"${account.name}" <${account.email}>`,
to: request.to.join(', '),
@@ -75,6 +97,12 @@ class MailSendSimpleService {
html: htmlContent,
});
console.log('✅ 메일 발송 성공:', {
messageId: info.messageId,
accepted: info.accepted,
rejected: info.rejected,
});
return {
success: true,
messageId: info.messageId,
@@ -83,6 +111,8 @@ class MailSendSimpleService {
};
} catch (error) {
const err = error as Error;
console.error('❌ 메일 발송 실패:', err.message);
console.error('❌ 에러 상세:', err);
return {
success: false,
error: err.message,
@@ -178,22 +208,42 @@ class MailSendSimpleService {
*/
async testConnection(accountId: string): Promise<{ success: boolean; message: string }> {
try {
console.log('🔌 SMTP 연결 테스트 시작:', accountId);
const account = await mailAccountFileService.getAccountById(accountId);
if (!account) {
throw new Error('계정을 찾을 수 없습니다.');
}
// 비밀번호 복호화
const decryptedPassword = encryptionService.decrypt(account.smtpPassword);
console.log('🔐 비밀번호 복호화 완료');
// 포트 465는 SSL/TLS를 사용해야 함
const isSecure = account.smtpPort === 465 ? true : (account.smtpSecure || false);
console.log('🔌 SMTP 연결 설정:', {
host: account.smtpHost,
port: account.smtpPort,
secure: isSecure,
user: account.smtpUsername,
});
const transporter = nodemailer.createTransport({
host: account.smtpHost,
port: account.smtpPort,
secure: account.smtpSecure,
secure: isSecure,
auth: {
user: account.smtpUsername,
pass: account.smtpPassword,
pass: decryptedPassword, // 복호화된 비밀번호 사용
},
connectionTimeout: 10000, // 10초 타임아웃
greetingTimeout: 10000,
});
console.log('🔌 SMTP 연결 검증 중...');
await transporter.verify();
console.log('✅ SMTP 연결 검증 성공!');
return {
success: true,
@@ -201,6 +251,7 @@ class MailSendSimpleService {
};
} catch (error) {
const err = error as Error;
console.error('❌ SMTP 연결 실패:', err.message);
return {
success: false,
message: `연결 실패: ${err.message}`,