-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend-test-email.mjs
More file actions
225 lines (205 loc) · 10.2 KB
/
send-test-email.mjs
File metadata and controls
225 lines (205 loc) · 10.2 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/**
* Quick script to send a test email via Ethereal (preview service)
* or real SMTP if configured.
*
* Usage: node send-test-email.mjs [template] [to-email]
*/
import nodemailer from "nodemailer";
const APP_URL = "https://tada.living";
// --- Template helpers (duplicated from server for standalone use) ---
function baseLayout(content) {
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ta-Da!</title>
<!--[if mso]>
<noscript><xml><o:OfficeDocumentSettings><o:PixelsPerInch>96</o:PixelsPerInch></o:OfficeDocumentSettings></xml></noscript>
<![endif]-->
</head>
<body style="margin: 0; padding: 0; background-color: #F5F0EB; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; -webkit-font-smoothing: antialiased;">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="background-color: #F5F0EB;">
<tr>
<td align="center" style="padding: 32px 16px;">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="max-width: 520px; background-color: #FFFFFF; border-radius: 12px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.08);">
<tr>
<td style="background-color: #2B0F3A; padding: 28px 32px; text-align: center;">
<a href="${APP_URL}" style="text-decoration: none;">
<!--[if mso]><table role="presentation" width="100%"><tr><td style="background-color: #2B0F3A; padding: 28px 32px; text-align: center;"><![endif]-->
<img src="${APP_URL}/icons/tada-logotype.png" alt="Ta-Da!" width="180" style="display: block; margin: 0 auto; max-width: 180px; height: auto; border: 0;" />
<!--[if mso]></td></tr></table><![endif]-->
</a>
</td>
</tr>
<tr>
<td style="padding: 32px;">
${content}
</td>
</tr>
<tr>
<td style="padding: 0 32px 28px 32px;">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="border-top: 1px solid #E7E5E4; padding-top: 20px; text-align: center;">
<p style="margin: 0 0 6px 0; font-size: 13px; color: #78716C;">
Sent from <a href="${APP_URL}" style="color: #E6A800; text-decoration: none; font-weight: 500;">Ta-Da!</a> — notice your life
</p>
<p style="margin: 0; font-size: 12px; color: #A8A29E;">
If you didn't request this email, you can safely ignore it.
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>`;
}
function ctaButton(label, url) {
return `<table role="presentation" cellpadding="0" cellspacing="0" border="0" style="margin: 24px auto;">
<tr>
<td align="center" style="background-color: #E6A800; border-radius: 8px;">
<!--[if mso]><v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" href="${url}" style="height:48px;v-text-anchor:middle;width:220px;" arcsize="17%" fillcolor="#E6A800"><center style="color:#ffffff;font-family:sans-serif;font-size:16px;font-weight:bold;">${label}</center></v:roundrect><![endif]-->
<!--[if !mso]><!-->
<a href="${url}" style="display: inline-block; padding: 14px 32px; background-color: #E6A800; color: #FFFFFF; text-decoration: none; font-size: 16px; font-weight: 600; border-radius: 8px; line-height: 1;">${label}</a>
<!--<![endif]-->
</td>
</tr>
</table>`;
}
function calloutBox(icon, text) {
return `<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="margin: 20px 0;">
<tr>
<td style="background-color: #FFFBF5; border-left: 3px solid #E6A800; padding: 12px 16px; border-radius: 0 6px 6px 0;">
<p style="margin: 0; font-size: 14px; color: #44403C;">${icon} ${text}</p>
</td>
</tr>
</table>`;
}
function fallbackLink(url) {
return `<p style="margin: 16px 0 0 0; font-size: 12px; color: #A8A29E; line-height: 1.5;">
If the button doesn't work, copy and paste this link into your browser:<br>
<a href="${url}" style="color: #E6A800; word-break: break-all;">${url}</a>
</p>`;
}
// --- Templates ---
const templates = {
verify: (username) => {
const url = `${APP_URL}/verify-email?token=test-preview-token`;
return {
subject: "Verify your Ta-Da! email",
html: baseLayout(`
<h2 style="margin: 0 0 8px 0; font-size: 22px; font-weight: 700; color: #1C1917;">Verify Your Email</h2>
<p style="margin: 0 0 20px 0; font-size: 15px; color: #57534E; line-height: 1.6;">
Hi ${username}, please confirm your email address so you can get the most out of Ta-Da!
</p>
${ctaButton("Verify Email", url)}
${calloutBox("⏰", "This link expires in 24 hours.")}
${fallbackLink(url)}
`),
};
},
welcome: (username) => ({
subject: "Welcome to Ta-Da! ⚡",
html: baseLayout(`
<h2 style="margin: 0 0 8px 0; font-size: 22px; font-weight: 700; color: #1C1917;">Welcome to Ta-Da! ⚡</h2>
<p style="margin: 0 0 20px 0; font-size: 15px; color: #57534E; line-height: 1.6;">
Hi ${username}, you're in! Ta-Da! is your space for celebrating what you do — sessions, wins, moments, and the rhythms that shape who you're becoming.
</p>
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="margin: 0 0 24px 0;">
<tr><td style="padding: 6px 0; font-size: 15px; color: #57534E;">⏱️ Timed sessions for meditation, focus, or creative flow</td></tr>
<tr><td style="padding: 6px 0; font-size: 15px; color: #57534E;">⚡ Ta-Da! wins — celebrate accomplishments big and small</td></tr>
<tr><td style="padding: 6px 0; font-size: 15px; color: #57534E;">✨ Moments — dreams, magic, gratitude, and reflections</td></tr>
<tr><td style="padding: 6px 0; font-size: 15px; color: #57534E;">📊 Tallies and rhythms that notice your patterns</td></tr>
</table>
${ctaButton("Get Started", APP_URL)}
`),
}),
supporter: (username) => ({
subject: "Welcome, Supporter! ⚡ Thank you for backing Ta-Da!",
html: baseLayout(`
<h2 style="margin: 0 0 8px 0; font-size: 22px; font-weight: 700; color: #1C1917;">Welcome, Supporter! ⚡</h2>
<p style="margin: 0 0 16px 0; font-size: 15px; color: #57534E; line-height: 1.6;">
Hi ${username},
</p>
<p style="margin: 0 0 16px 0; font-size: 15px; color: #57534E; line-height: 1.6;">
I'm genuinely delighted you've chosen to support Ta-Da! It means a huge amount to me personally.
</p>
<p style="margin: 0 0 16px 0; font-size: 15px; color: #57534E; line-height: 1.6;">
I built Ta-Da! because I believe we should spend more time noticing the good things in our lives. The things we do, the small wins, the quiet moments. Your support helps keep it independent, ad-free, and focused on what matters.
</p>
<p style="margin: 0 0 8px 0; font-size: 15px; color: #57534E; line-height: 1.6;">
As a supporter you get:
</p>
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="margin: 0 0 24px 0;">
<tr><td style="padding: 6px 0; font-size: 15px; color: #57534E;">🌳 Unlimited data retention — your journey is yours forever</td></tr>
<tr><td style="padding: 6px 0; font-size: 15px; color: #57534E;">☁️ Priority access to new features as they're built</td></tr>
<tr><td style="padding: 6px 0; font-size: 15px; color: #57534E;">💛 The knowledge you're funding mindful, independent software</td></tr>
</table>
<p style="margin: 0 0 20px 0; font-size: 15px; color: #57534E; line-height: 1.6;">
If you ever have ideas, feedback, or just want to say hello, reply to this email. I read every message.
</p>
${ctaButton("Continue to Ta-Da!", APP_URL)}
<p style="margin: 24px 0 0 0; font-size: 15px; color: #57534E; line-height: 1.6;">
With gratitude,<br>
<strong style="color: #1C1917;">Caspar</strong><br>
<span style="font-size: 13px; color: #78716C;">Creator of Ta-Da!</span>
</p>
`),
}),
};
// --- Main ---
const templateName = process.argv[2] || "verify";
const toEmail = process.argv[3] || "infantologist@gmail.com";
const username = "infantologist";
const templateFn = templates[templateName];
if (!templateFn) {
console.error(`Unknown template: ${templateName}`);
console.error(`Available: ${Object.keys(templates).join(", ")}`);
process.exit(1);
}
const email = templateFn(username);
// Check for real SMTP config
const smtpHost = process.env.SMTP_HOST;
const smtpUser = process.env.SMTP_USER;
const smtpPass = process.env.SMTP_PASSWORD;
let transporter;
let isEthereal = false;
if (smtpHost && smtpUser && smtpPass) {
console.log(`Using real SMTP: ${smtpHost}`);
transporter = nodemailer.createTransport({
host: smtpHost,
port: parseInt(process.env.SMTP_PORT || "587"),
secure: process.env.SMTP_SECURE === "true",
auth: { user: smtpUser, pass: smtpPass },
});
} else {
console.log("No SMTP configured — using Ethereal test service...");
const testAccount = await nodemailer.createTestAccount();
transporter = nodemailer.createTransport({
host: "smtp.ethereal.email",
port: 587,
secure: false,
auth: { user: testAccount.user, pass: testAccount.pass },
});
isEthereal = true;
}
console.log(`Sending "${templateName}" email to ${toEmail}...`);
const info = await transporter.sendMail({
from: '"Ta-Da!" <hello@tada.living>',
to: toEmail,
subject: `[TEST] ${email.subject}`,
html: email.html,
});
console.log(`\n✅ Email sent! Message ID: ${info.messageId}`);
if (isEthereal) {
const previewUrl = nodemailer.getTestMessageUrl(info);
console.log(`\n📧 Preview URL (open in browser):\n${previewUrl}`);
console.log(`\n(This is an Ethereal preview — it won't arrive in your real inbox.`);
console.log(`To send to your real inbox, configure SMTP_HOST/USER/PASSWORD in .env)`);
}