1
+ import express from "express" ;
2
+ import bodyParser from "body-parser" ;
3
+ import cors from "cors" ;
4
+ import { exec } from "child_process" ;
5
+
6
+ const app = express ( ) ;
7
+ const PORT = 3000 ;
8
+
9
+ app . use ( cors ( ) ) ;
10
+ app . use ( bodyParser . json ( ) ) ;
11
+
12
+ app . post ( "/api/send-email" , ( req , res ) => {
13
+ const { formData } = req . body ;
14
+
15
+ if ( ! formData ) {
16
+ return res . status ( 400 ) . json ( { error : "Form data is required." } ) ;
17
+ }
18
+
19
+ // Format the email content
20
+ const emailBody = `
21
+
22
+
23
+ Subject: Request Access Form Submission
24
+
25
+ Personal Information:
26
+ Name: ${ formData . name }
27
+ Email: ${ formData . email }
28
+ Phone: ${ formData . phone }
29
+
30
+ Professional Information:
31
+ Company Name: ${ formData . companyName }
32
+ Job Title: ${ formData . jobTitle }
33
+ Industry: ${ formData . industry }
34
+ Company Size: ${ formData . companySize }
35
+ Country: ${ formData . country }
36
+
37
+ Areas of Interest:
38
+ - Document Management: ${ formData . interests . documentManagement ? 'Yes' : 'No' }
39
+ - Workflow Automation: ${ formData . interests . workflowAutomation ? 'Yes' : 'No' }
40
+ - AI Content Analysis: ${ formData . interests . aiContentAnalysis ? 'Yes' : 'No' }
41
+ - Collaboration Tools: ${ formData . interests . collaborationTools ? 'Yes' : 'No' }
42
+
43
+ Additional Information:
44
+ Communication Preference: ${ formData . communicationPreference }
45
+ Timeframe: ${ formData . timeframe }
46
+ Source: ${ formData . source }
47
+ Marketing Consent: ${ formData . marketingConsent ? 'Yes' : 'No' }
48
+
49
+ Comments:
50
+ ${ formData . comments }
51
+
52
+ Submission Time: ${ new Date ( ) . toISOString ( ) }
53
+ ` ;
54
+
55
+ // Send email using msmtp
56
+ exec ( `echo "${ emailBody } " | msmtp -t` , ( error , stdout , stderr ) => {
57
+ if ( error ) {
58
+ console . error ( "Error sending email:" , stderr ) ;
59
+ return res . status ( 500 ) . json ( { error : "Failed to send the email." } ) ;
60
+ }
61
+
62
+ console . log ( "Email sent successfully:" , stdout ) ;
63
+ res . status ( 200 ) . json ( { message : "Email sent successfully." } ) ;
64
+ } ) ;
65
+ } ) ;
66
+
67
+ app . listen ( PORT , ( ) => {
68
+ console . log ( `Server is running on http://localhost:${ PORT } ` ) ;
69
+ } ) ;
0 commit comments