-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
48 lines (37 loc) · 1.04 KB
/
main.js
File metadata and controls
48 lines (37 loc) · 1.04 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
import "dotenv/config";
import nodemailer from "nodemailer"
function formatMessageText({name, email, phone, message}) {
return `
New contact form submission received at ${(new Date()).toString()}
Name: ${name}
Email: ${email}
Phone: ${phone ?? ""}
Message:
${message}
`
}
async function main() {
const {GMAIL_EMAIL, GMAIL_APP_PASSWORD, RECIPIENT_EMAIL} = process.env;
const submissionData = {
"name": "Michael G. Scott",
"email": "worlds.best.boss@dundermifflin.com",
"message": "Would I rather be feared or loved? Easy. Both. I want people to be afraid of how much they love me."
}
const client = nodemailer.createTransport({
service: "Gmail",
auth: {
user: GMAIL_EMAIL,
pass: GMAIL_APP_PASSWORD
}
});
const result = await client.sendMail(
{
from: GMAIL_EMAIL,
to: RECIPIENT_EMAIL,
subject: `Portfolio Contact Form: ${submissionData.name}`,
text: formatMessageText(submissionData)
}
)
console.log(result);
}
main();