Skip to content

Commit

Permalink
feat: 방명록 등록 시 나에게 이메일 전송
Browse files Browse the repository at this point in the history
  • Loading branch information
metacode22 committed Sep 24, 2024
1 parent beda5e9 commit f351a95
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/api/guestbooks/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NextRequest, NextResponse } from 'next/server';
import nodemailer from 'nodemailer';

import { prisma } from '@/src/utils/prisma';
import { stringifyBigIntId } from '@/src/utils/stringify-big-int-id';
Expand All @@ -21,5 +22,24 @@ export async function POST(request: NextRequest) {
},
});

const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: process.env.GOOGLE_APP_PASSWORD,
},
});

try {
await transporter.sendMail({
from: '[email protected]',
to: '[email protected]',
subject: '블로그에 방명록이 등록되었습니다.',
text: `${name}: ${message}`,
});
} catch (error) {
console.error(error);
}

return NextResponse.json({ guestbook: stringifyBigIntId(guestbook) });
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"next": "^14.2.5",
"next-mdx-remote": "^4",
"next-sitemap": "^4.2.3",
"nodemailer": "^6.9.15",
"postcss": "8.4.30",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand All @@ -43,6 +44,7 @@
"devDependencies": {
"@tailwindcss/typography": "^0.5.10",
"@types/gtag.js": "^0.0.18",
"@types/nodemailer": "^6.4.16",
"eslint-plugin-simple-import-sort": "^12.0.0",
"prettier-plugin-tailwindcss": "^0.5.4",
"prisma": "^5.18.0",
Expand Down
19 changes: 19 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f351a95

Please sign in to comment.