-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Janaka-Steph
committed
Oct 19, 2022
1 parent
0ed7549
commit 4107e5f
Showing
8 changed files
with
132 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
PUBLIC_URL=/function/bitcoin-studio-client | ||
REACT_APP_SEND_EMAIL_URL=/api/send-email | ||
REACT_APP_SEND_EMAIL_URL=/.netlify/functions/send-email | ||
SMTP_GMAIL_PASS=*** | ||
SMTP_GMAIL_USER=***@gmail.com | ||
PORT=8081 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,6 @@ logs | |
*.log | ||
|
||
# Misc | ||
commands.adoc | ||
commands.adoc | ||
# Local Netlify folder | ||
.netlify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
14 | ||
16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {Handler} from '@netlify/functions' | ||
import nodemailer from 'nodemailer' | ||
|
||
export const handler: Handler = async (event, context) => { | ||
try { | ||
if (!event.body) throw new Error('event.body missing') | ||
const data = JSON.parse(event.body); | ||
const transporter = nodemailer.createTransport({ | ||
host: 'smtp.gmail.com', | ||
port: 465, | ||
secure: true, | ||
auth: { | ||
user: process.env.SMTP_GMAIL_USER, | ||
pass: process.env.SMTP_GMAIL_PASS | ||
} | ||
}); | ||
const mailOptions = { | ||
from: `"${data.from_name}" <${data.from_email}>`, | ||
to: '[email protected]', | ||
subject: 'Bitcoin Studio Website Form', | ||
text: data.message | ||
} | ||
const messageInfo = await transporter.sendMail(mailOptions); | ||
console.log('messageInfo', messageInfo); | ||
return { | ||
statusCode: 200, | ||
body: JSON.stringify({message: "Mail sent successfully"}), | ||
headers: {'Content-Type': 'application/json'} | ||
}; | ||
} catch (error) { | ||
console.error(error); | ||
return { | ||
statusCode: 500, | ||
body: JSON.stringify({error: (error as any).message}), | ||
headers: {'Content-Type': 'application/json'} | ||
}; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.