0
Send app report
One script reply has been approved by the moderators Verified
Created by hugo697 144 days ago Viewed 4310 times
0
Submitted by hugo697 Bun
Verified 144 days ago
1
import nodemailer from "nodemailer";
2
type Smtp = {
3
  host: string;
4
  port: number;
5
  user: string;
6
  password: string;
7
};
8
type Base64 = string
9
export async function main(
10
  smtp: Smtp,
11
  screenshot: Base64,
12
  kind: 'pdf' | 'png',
13
  to_email: string,
14
  from_email: string,
15
  app_path: string,
16
) {
17
  const transporter = nodemailer.createTransport({
18
    host: smtp.host,
19
    port: smtp.port,
20
    secure: true,
21
    auth: {
22
      user: smtp.user,
23
      pass: smtp.password,
24
    },
25
  });
26
  const fullAppPath = Bun.env["WM_BASE_URL"] + '/apps/get/' + app_path + '?workspace=' + Bun.env["WM_WORKSPACE"]
27
  return await transporter.sendMail({
28
    from: from_email,
29
    to: to_email,
30
    subject: "App report of " + app_path,
31
    html: "<p>App report of <a href='" + fullAppPath + "'>" + app_path + "</a></p>",
32
    attachments: [
33
      {
34
        filename: "report." + kind,
35
        content: Buffer.from(screenshot, "base64"),
36
      },
37
    ],
38
  });
39
}