-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemailjs-setup.js
More file actions
211 lines (181 loc) · 6.08 KB
/
emailjs-setup.js
File metadata and controls
211 lines (181 loc) · 6.08 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
#!/usr/bin/env node
/**
* EmailJS Setup Helper Script
*
* This script helps you configure EmailJS for your contact form.
* Run: node emailjs-setup.js
*/
import fs from "fs";
import path from "path";
import readline from "readline";
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const colors = {
reset: "\x1b[0m",
bright: "\x1b[1m",
green: "\x1b[32m",
blue: "\x1b[34m",
yellow: "\x1b[33m",
cyan: "\x1b[36m",
red: "\x1b[31m",
};
function colorize(text, color) {
return `${colors[color]}${text}${colors.reset}`;
}
function question(query) {
return new Promise((resolve) => rl.question(query, resolve));
}
async function main() {
console.log("\n" + colorize("=".repeat(60), "cyan"));
console.log(colorize("📧 EmailJS Configuration Setup", "bright"));
console.log(colorize("=".repeat(60), "cyan") + "\n");
console.log(
colorize(
"This script will help you configure EmailJS for your contact form.\n",
"blue"
)
);
// Check if .env exists
const envPath = path.join(__dirname, ".env");
const envExamplePath = path.join(__dirname, ".env.example");
if (!fs.existsSync(envPath)) {
console.log(
colorize(
"⚠️ .env file not found. Creating from .env.example...",
"yellow"
)
);
if (fs.existsSync(envExamplePath)) {
fs.copyFileSync(envExamplePath, envPath);
console.log(colorize("✅ .env file created!\n", "green"));
} else {
console.log(
colorize(
"❌ .env.example not found. Creating new .env file...\n",
"red"
)
);
}
}
// Step 1: Instructions
console.log(colorize("Step 1: Create EmailJS Account", "bright"));
console.log(" 1. Go to: " + colorize("https://www.emailjs.com/", "cyan"));
console.log(" 2. Sign up or log in to your account\n");
await question(colorize("Press Enter when you have logged in...", "yellow"));
// Step 2: Email Service
console.log("\n" + colorize("Step 2: Set up Email Service", "bright"));
console.log(
" 1. In EmailJS dashboard, go to " + colorize("Email Services", "cyan")
);
console.log(" 2. Click " + colorize("Add New Service", "cyan"));
console.log(" 3. Choose your email provider (Gmail, Outlook, etc.)");
console.log(" 4. Follow the setup instructions");
console.log(
" 5. Copy your " +
colorize("Service ID", "green") +
" (e.g., service_abc1234)\n"
);
const serviceId = await question(
colorize("Enter your Service ID: ", "yellow")
);
// Step 3: Email Template
console.log("\n" + colorize("Step 3: Create Email Template", "bright"));
console.log(
" 1. In EmailJS dashboard, go to " + colorize("Email Templates", "cyan")
);
console.log(" 2. Click " + colorize("Create New Template", "cyan"));
console.log(" 3. Use these variables in your template:");
console.log(
" - " + colorize("{{from_name}}", "green") + " - Sender's name"
);
console.log(
" - " + colorize("{{from_email}}", "green") + " - Sender's email"
);
console.log(
" - " + colorize("{{message}}", "green") + " - Message content"
);
console.log(
" - " +
colorize("{{to_name}}", "green") +
" - Your name (Srinivas Koruprolu)"
);
console.log(
" 4. Save and copy your " +
colorize("Template ID", "green") +
" (e.g., template_xyz5678)\n"
);
const templateId = await question(
colorize("Enter your Template ID: ", "yellow")
);
// Step 4: Public Key
console.log("\n" + colorize("Step 4: Get Public Key", "bright"));
console.log(
" 1. In EmailJS dashboard, go to " + colorize("Account", "cyan")
);
console.log(
" 2. Copy your " + colorize("Public Key", "green") + " (User ID)\n"
);
const publicKey = await question(
colorize("Enter your Public Key: ", "yellow")
);
// Validate inputs
if (!serviceId.trim() || !templateId.trim() || !publicKey.trim()) {
console.log("\n" + colorize("❌ Error: All fields are required!", "red"));
rl.close();
return;
}
// Update .env file
try {
let envContent = fs.readFileSync(envPath, "utf8");
// Replace or add EmailJS variables
const updates = {
VITE_EMAILJS_SERVICE_ID: serviceId.trim(),
VITE_EMAILJS_TEMPLATE_ID: templateId.trim(),
VITE_EMAILJS_PUBLIC_KEY: publicKey.trim(),
};
for (const [key, value] of Object.entries(updates)) {
const regex = new RegExp(`^${key}=.*$`, "m");
if (regex.test(envContent)) {
envContent = envContent.replace(regex, `${key}=${value}`);
} else {
envContent += `\n${key}=${value}`;
}
}
fs.writeFileSync(envPath, envContent);
console.log("\n" + colorize("=".repeat(60), "green"));
console.log(colorize("✅ Configuration Saved Successfully!", "bright"));
console.log(colorize("=".repeat(60), "green"));
console.log("\n" + colorize("📋 Your Configuration:", "bright"));
console.log(" Service ID: " + colorize(serviceId.trim(), "cyan"));
console.log(" Template ID: " + colorize(templateId.trim(), "cyan"));
console.log(
" Public Key: " +
colorize(publicKey.trim().substring(0, 10) + "...", "cyan")
);
console.log("\n" + colorize("🚀 Next Steps:", "bright"));
console.log(" 1. Restart your development server:");
console.log(" " + colorize("npm run dev", "green"));
console.log(" 2. Test the contact form on your site");
console.log(" 3. Check your email for the test message\n");
console.log(colorize("💡 Tip:", "yellow") + " If the form doesn't work:");
console.log(" - Check browser console for errors");
console.log(" - Verify your EmailJS credentials");
console.log(" - Make sure your email service is active\n");
} catch (error) {
console.log(
"\n" + colorize("❌ Error saving configuration:", "red"),
error.message
);
}
rl.close();
}
main().catch((error) => {
console.error(colorize("❌ Error:", "red"), error);
rl.close();
process.exit(1);
});