1
1
const router = require ( "express" ) . Router ( ) ;
2
2
const moment = require ( "moment" ) ;
3
+ const nodemailer = require ( "nodemailer" ) ;
3
4
const { google } = require ( "googleapis" ) ;
4
5
require ( "dotenv" ) . config ( ) ;
5
6
@@ -10,6 +11,24 @@ const client = new google.auth.JWT(
10
11
[ "https://www.googleapis.com/auth/spreadsheets" ]
11
12
) ;
12
13
14
+ const transporter = nodemailer . createTransport ( {
15
+ host : process . env . SMTP_HOST ,
16
+ port : process . env . SMTP_PORT ,
17
+ secure : true ,
18
+ auth : {
19
+ user : process . env . SMTP_USER ,
20
+ pass : process . env . SMTP_PASS ,
21
+ } ,
22
+ } ) ;
23
+
24
+ transporter . verify ( function ( error , success ) {
25
+ if ( error ) {
26
+ console . log ( "Email Server Error: " + error ) ;
27
+ } else {
28
+ console . log ( "Email Server is ready to take our messages" ) ;
29
+ }
30
+ } ) ;
31
+
13
32
client . authorize ( function ( err ) {
14
33
if ( err ) {
15
34
console . log ( err ) ;
@@ -51,6 +70,28 @@ router.post("/get-involved", async (req, res) => {
51
70
} ,
52
71
} ;
53
72
73
+ var mailOptions = {
74
+ from : process . env . SMTP_USER ,
75
+ to : process . env . INFO_EMAIL ,
76
+ subject : "New kcsoc.com Form Entry: Get Involved" ,
77
+ text : `
78
+ You have got a new response on the kcsoc.com Get Involved Form!
79
+ Please find further details below.
80
+
81
+ Name: ${ firstName } ${ lastName }
82
+ University: ${ university }
83
+ Email: ${ email }
84
+ Phone Number: ${ phoneNumber }
85
+ ` ,
86
+ } ;
87
+ transporter . sendMail ( mailOptions , function ( error , info ) {
88
+ if ( error ) {
89
+ console . log ( error ) ;
90
+ } else {
91
+ console . log ( "Email sent: " + info . response ) ;
92
+ }
93
+ } ) ;
94
+
54
95
await gsapi . spreadsheets . values . append ( updateOptions ) ;
55
96
return res . status ( 201 ) . send ( { msg : "Form submission accepted" } ) ;
56
97
} catch ( e ) {
@@ -81,6 +122,27 @@ router.post("/set-up-a-kcsoc", async (req, res) => {
81
122
} ,
82
123
} ;
83
124
125
+ var mailOptions = {
126
+ from : process . env . SMTP_USER ,
127
+ to : process . env . INFO_EMAIL ,
128
+ subject : "New kcsoc.com Form Entry: Set Up a KCSoc" ,
129
+ text : `
130
+ You have got a new response on the kcsoc.com Get Involved Form!
131
+ Please find further details below.
132
+
133
+ Name: ${ firstName } ${ lastName }
134
+ Email: ${ email }
135
+ Phone Number: ${ phoneNumber }
136
+ ` ,
137
+ } ;
138
+ transporter . sendMail ( mailOptions , function ( error , info ) {
139
+ if ( error ) {
140
+ console . log ( error ) ;
141
+ } else {
142
+ console . log ( "Email sent: " + info . response ) ;
143
+ }
144
+ } ) ;
145
+
84
146
await gsapi . spreadsheets . values . append ( updateOptions ) ;
85
147
return res . status ( 201 ) . send ( { msg : "Form submission accepted" } ) ;
86
148
} catch ( e ) {
0 commit comments