eletrotupi / tcc/ api/src/lib/mail.ts9cd93e6ab48e317d51b0bdf9066dc5852cda738f
652 B | 20 lines Raw
1
import { Resend } from 'resend';
2

3
// Built on first send, not at import: a module that reads a secret at import
4
// time makes every importer require it, so a missing RESEND_API_KEY crashes
5
// app boot and any test that transitively imports this file.
6
let client: Resend | undefined;
7

8
const getResend = (): Resend => {
9
  if (!client) client = new Resend(process.env.RESEND_API_KEY);
10

11
  return client;
12
};
13

14
// XXX: Bleh, resend doesn't expose their types so w/e
15
export async function sendEmail(opts: any): Promise<any> {
16
  return await getResend().emails.send({
17
    from: process.env.RESEND_FROM ?? 'naoresponda@updates.cabotia.dev',
18
    ...opts,
19
  });
20
}