Repository navigation
Expand file tree
/
Copy pathtest-smtp.ts
More file actions
83 lines (74 loc) · 2.33 KB
/
Copy pathtest-smtp.ts
File metadata and controls
83 lines (74 loc) · 2.33 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { render } from "@react-email/render";
import nodemailer from "nodemailer";
import React from "react";
import { InviteEmail } from "./apps/backend/email/emails/invite";
import { OTPTokenEmail } from "./apps/backend/email/emails/otp";
import { WelcomeEmail } from "./apps/backend/email/emails/welcome";
async function run() {
const recipient = process.argv[2] || "gogo@local.reloop.sh";
const baseUrl = "https://local.reloop.sh";
const transporter = nodemailer.createTransport({
host: "localhost",
port: 25,
secure: false,
tls: {
rejectUnauthorized: false,
},
});
// Define multiple email templates and configurations to send
const emails = [
{
name: "OTP Code Email",
from: `"Reloop Security" <security@local.reloop.sh>`,
subject: "Your login code for Reloop",
text: "Your login code for Reloop is 241237",
element: React.createElement(OTPTokenEmail, {
otp: "241237",
email: recipient,
baseUrl,
}),
},
{
name: "Welcome Email",
from: `"Reloop Team" <team@local.reloop.sh>`,
subject: "Welcome to Reloop! Open-source email infrastructure",
text: "Welcome to Reloop! Open-source email infrastructure built for scale.",
element: React.createElement(WelcomeEmail, {
fullName: "John Doe",
baseUrl,
theme: "light",
}),
},
{
name: "Team Invite Email",
from: `"Reloop Invites" <invite@local.reloop.sh>`,
subject: "Join Reloop Alpha team on Reloop",
text: "Alice Smith has invited you to the Reloop Alpha team.",
element: React.createElement(InviteEmail, {
inviteeName: "John Doe",
inviterName: "Alice Smith",
inviterEmail: "alice@local.reloop.sh",
teamName: "Reloop Alpha",
inviteUrl: `${baseUrl}/invite/reloop-alpha-123`,
baseUrl,
theme: "dark",
}),
},
];
console.log(`🚀 Starting test email batch send to: ${recipient}`);
for (const email of emails) {
console.log(`\n⏳ Rendering ${email.name}...`);
const html = await render(email.element);
console.log(`⏳ Sending ${email.name} from: ${email.from}...`);
const info = await transporter.sendMail({
from: email.from,
to: recipient,
subject: email.subject,
text: email.text,
html,
});
console.log(`✅ ${email.name} sent successfully! ID: ${info.messageId}`);
}
console.log("\n🎉 All test emails have been sent successfully!");
}
run().catch(console.error);