-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact.js
51 lines (47 loc) · 1.25 KB
/
contact.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
const nodemailer = require("nodemailer");
exports.handler = async (event) => {
const contactEmail = nodemailer.createTransport({
host: "smtp.example.com",
port: 465,
secure: true,
service: "gmail",
auth: {
user: "[email protected]",
pass: "zkxaugunplsjlpsw",
},
});
contactEmail.verify((error) => {
if (error) {
console.log(error);
} else {
console.log("Ready to Send");
}
});
const name =
event.queryStringParameters.firstName +
event.queryStringParameters.lastName;
const email = event.queryStringParameters.email;
const message = event.queryStringParameters.message;
const phone = event.queryStringParameters.phone;
const mail = {
from: name,
to: "[email protected]",
subject: "Contact Form Submission - Portfolio",
html: `<p>Name: ${name}</p>
<p>Email: ${email}</p>
<p>Phone: ${phone}</p>
<p>Message: ${message}</p>`,
};
try {
await contactEmail.sendMail(mail);
return {
statusCode: 200,
body: JSON.stringify({ code: 200, status: "Message Sent" }),
};
} catch (error) {
return {
statusCode: 500,
body: JSON.stringify({ code: 500, status: "Internal Server Error" }),
};
}
};