-
Notifications
You must be signed in to change notification settings - Fork 18
/
+handler.ts
37 lines (32 loc) · 1.02 KB
/
+handler.ts
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
import type { FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox';
import { Type } from '@sinclair/typebox';
import nodemailer from 'nodemailer';
import nunjucks from 'nunjucks';
import useMailer from '~/composables/useMailer';
import helloWorld from '~/templates/hello-world.html?raw';
export default (async (app) => {
/*
$ curl --request GET \
--url http://127.0.0.1:3000/api/email
*/
app.get(
'',
{
schema: {
response: { '2xx': { messageId: Type.String() } },
},
},
async (req, reply) => {
const mailer = useMailer();
const info = await mailer.sendMail({
to: '[email protected], [email protected]',
subject: 'Hello ✔',
html: nunjucks.renderString(helloWorld, { hello: 'Hello, MJML!' }),
});
if (process.env.NODE_ENV === 'development') {
console.log('TestMessageUrl =', nodemailer.getTestMessageUrl(info));
}
return reply.send({ messageId: info.messageId });
},
);
}) as FastifyPluginAsyncTypebox;