-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
69 lines (55 loc) · 1.99 KB
/
server.js
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
import express from "express";
import bodyParser from "body-parser";
import cors from "cors";
import { exec } from "child_process";
const app = express();
const PORT = 3000;
app.use(cors());
app.use(bodyParser.json());
app.post("/api/send-email", (req, res) => {
const { formData } = req.body;
if (!formData) {
return res.status(400).json({ error: "Form data is required." });
}
// Format the email content
const emailBody = `
From: [email protected]
Subject: Request Access Form Submission
Personal Information:
Name: ${formData.name}
Email: ${formData.email}
Phone: ${formData.phone}
Professional Information:
Company Name: ${formData.companyName}
Job Title: ${formData.jobTitle}
Industry: ${formData.industry}
Company Size: ${formData.companySize}
Country: ${formData.country}
Areas of Interest:
- Document Management: ${formData.interests.documentManagement ? 'Yes' : 'No'}
- Workflow Automation: ${formData.interests.workflowAutomation ? 'Yes' : 'No'}
- AI Content Analysis: ${formData.interests.aiContentAnalysis ? 'Yes' : 'No'}
- Collaboration Tools: ${formData.interests.collaborationTools ? 'Yes' : 'No'}
Additional Information:
Communication Preference: ${formData.communicationPreference}
Timeframe: ${formData.timeframe}
Source: ${formData.source}
Marketing Consent: ${formData.marketingConsent ? 'Yes' : 'No'}
Comments:
${formData.comments}
Submission Time: ${new Date().toISOString()}
`;
// Send email using msmtp
exec(`echo "${emailBody}" | msmtp -t`, (error, stdout, stderr) => {
if (error) {
console.error("Error sending email:", stderr);
return res.status(500).json({ error: "Failed to send the email." });
}
console.log("Email sent successfully:", stdout);
res.status(200).json({ message: "Email sent successfully." });
});
});
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});