Skip to content

Commit fbf8f14

Browse files
committed
feat: 이메일 전송
1 parent 3a10ccc commit fbf8f14

File tree

2 files changed

+77
-5
lines changed

2 files changed

+77
-5
lines changed

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"typescript": "^5.5.3"
1515
},
1616
"dependencies": {
17-
"@aws-sdk/client-ses": "^3.616.0",
18-
"@aws-sdk/client-sqs": "^3.616.0"
17+
"@aws-sdk/client-ses": "^3.616.0"
1918
}
2019
}

src/index.ts

+76-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,78 @@
1-
import { Handler } from 'aws-lambda';
1+
import { SQSHandler, SQSEvent } from 'aws-lambda';
2+
import { SESClient, SendEmailCommand } from '@aws-sdk/client-ses';
23

3-
export const handler: Handler = async (event) => {
4-
console.log(event);
4+
export const handler: SQSHandler = async (event: SQSEvent) => {
5+
const body = event.Records[0]!.body;
6+
const message = JSON.parse(body) as ReservationMessage;
7+
8+
const sesClient = new SESClient();
9+
10+
const githubRepoUrl = 'https://github.com/project-notification/readme/issues';
11+
12+
const htmlBody = `
13+
<html>
14+
<body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333;">
15+
<div style="max-width: 600px; margin: 0 auto; padding: 20px;">
16+
<h1 style="color: #4a4a4a;">새로운 프로젝트 알림</h1>
17+
<p>안녕하세요,</p>
18+
<p>새로운 프로젝트가 등록되었습니다:</p>
19+
<div style="background-color: #f0f0f0; padding: 15px; border-radius: 5px;">
20+
<h2 style="color: #2c3e50; margin-top: 0;">${message.title}</h2>
21+
<p>자세한 내용을 보려면 아래 링크를 클릭하세요:</p>
22+
<a href="${
23+
message.url
24+
}" style="display: inline-block; padding: 10px 20px; background-color: #3498db; color: white; text-decoration: none; border-radius: 5px;">프로젝트 보기</a>
25+
</div>
26+
${
27+
message.topics
28+
? `
29+
<div style="margin-top: 20px;">
30+
<p>관련 주제:</p>
31+
<ul>
32+
${message.topics.map((topic) => `<li>${topic}</li>`).join('')}
33+
</ul>
34+
</div>
35+
`
36+
: ''
37+
}
38+
<p style="margin-top: 20px;">이 알림이 도움이 되셨기를 바랍니다.</p>
39+
<div style="margin-top: 30px; padding: 15px; background-color: #e7f3fe; border-left: 5px solid #2196F3; border-radius: 4px;">
40+
<p><strong>알림 구독 해제 방법:</strong></p>
41+
<p>더 이상 이메일 알림을 받지 않으려면, 아래 GitHub 저장소에서 귀하의 이슈를 닫아주세요:</p>
42+
<a href="${githubRepoUrl}" style="color: #2196F3; text-decoration: none;">GitHub 저장소 방문하기</a>
43+
</div>
44+
<p style="margin-top: 20px;">감사합니다.</p>
45+
</div>
46+
</body>
47+
</html>
48+
`;
49+
50+
const command = new SendEmailCommand({
51+
Destination: {
52+
ToAddresses: [message.email],
53+
},
54+
Message: {
55+
Body: {
56+
Html: {
57+
Data: htmlBody,
58+
},
59+
Text: {
60+
Data: `새로운 프로젝트가 등록되었습니다. ${message.title} 자세한 내용: ${message.url}\n\n알림 구독 해제: 더 이상 알림을 받지 않으려면 다음 GitHub 저장소에서 귀하의 이슈를 닫아주세요: ${githubRepoUrl}`,
61+
},
62+
},
63+
Subject: {
64+
Data: `새 프로젝트 알림: ${message.title}`,
65+
},
66+
},
67+
Source: '[email protected]',
68+
});
69+
70+
await sesClient.send(command);
71+
};
72+
73+
type ReservationMessage = {
74+
email: string;
75+
title: string;
76+
url: string;
77+
topics?: string[];
578
};

0 commit comments

Comments
 (0)