eletrotupi / tcc/ api/src/services/mail/welcome.tsbd62b645a9dc9b775e0e82f727d61f17fbdbdcee
727 B | 31 lines Raw
1
import { findUserById } from '@app/services/user.service';
2
import { sendEmail }  from '@app/lib/mail';
3

4
const email = (firstName: string) => {
5
  return (`
6
Oi! Seja bem vindo, ${firstName}.
7

8
Você criou sua conta com sucesso no orbit!
9

10
Qualquer coisa prende o grito!
11
  `)
12
}
13

14
export async function sendWelcomeEmail(userId: number): Promise<void> {
15
  const user = await findUserById(userId)!;
16

17
  console.log("Email/welcome: ", user);
18

19
  const { data, error } = await sendEmail({
20
    to: user!.email,
21
    subject: "Bem vindo ao orbit!",
22
    text: email(user!.firstName)
23
  });
24

25
  if (error) {
26
    console.error("Error sending email: ", error);
27
  }
28

29
  console.log("Email sent successfully!");
30
  console.log("Email ID:", data?.id);
31
}