-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmessage.ts
More file actions
28 lines (22 loc) · 780 Bytes
/
message.ts
File metadata and controls
28 lines (22 loc) · 780 Bytes
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
import { createKoaRouter, withKoaRouter } from 'next-ssr-middleware';
import { createTransport } from 'nodemailer';
import Mail from 'nodemailer/lib/mailer';
import {
SMTP_HOST,
SMTP_PASSWORD,
SMTP_PORT,
SMTP_USER,
} from '../../../../../models/configuration';
export const config = { api: { bodyParser: false } };
const router = createKoaRouter(import.meta.url),
transporter = createTransport({
host: SMTP_HOST,
port: +SMTP_PORT,
secure: +SMTP_PORT === 465,
auth: { user: SMTP_USER, pass: SMTP_PASSWORD },
});
router.post('/bot/message', async context => {
const input = Reflect.get(context.request, 'body') as Mail.Options;
context.body = await transporter.sendMail({ ...input, from: SMTP_USER });
});
export default withKoaRouter(router);