From 239c7cd754bf5d170852d8f481905cb8f655aa88 Mon Sep 17 00:00:00 2001 From: Yash Kadulkar Date: Wed, 5 Oct 2022 15:30:29 +0530 Subject: [PATCH 1/2] Added backend. Emailing the messages received from users using backend (express) --- backend/app.js | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 backend/app.js diff --git a/backend/app.js b/backend/app.js new file mode 100644 index 0000000..9e4bd5d --- /dev/null +++ b/backend/app.js @@ -0,0 +1,68 @@ +//jshint esversion:6 +const express = require("express"); +const bodyParser = require("body-parser"); +const nodemailer = require('nodemailer'); + +const app = express(); +app.use(bodyParser.urlencoded({ extended: true })); +app.use(express.static("../")) + +app.get("/", (req, res) => { + res.redirect("index.html"); +}); + +app.post("/", (req, res) => { + const name = req.body.name; + const email = req.body.email; + const message = req.body.message; + + // YOUR EMAIL AUTHENTICATION REQUIRED + /* NOTE: REGULAR LOGIN PASSWORD WILL NOT WORK HERE IF TWO-FACTOR AUTHENTICATION IS ENABLED ON YOUR PROXY GOOGLE ACCOUNT. + THIS NEEDS AN APP-SPECIFIC PASSWORD + */ + + /* + To generate your App-Specific Password follow these instructions: + 1. Follow this link - https://myaccount.google.com/u/0/security?hl=en + Make sure you are on the proxy google account only. + 2. Under the section named "Sigining in to Google" click on "App Passwords" + 3. Verify it’s you by using the regular google account password + 4. Select App -> Other (Custom name) + 5. Click on "Generate" + 6. Copy this generated password into the "pass" field down here + 7. Voila! You are receiving messages via your proxy email when new users send any message + */ + var transporter = nodemailer.createTransport({ + service: 'gmail', + auth: { + user: '', // proxy email address + pass: '' // If 2FA is enabled for this google account, app-specific password to be generated following the instructions. + } + }); + + const mailData = { + from: 'yashkadulkar3@gmail.com', // proxy sender address + to: 'info@bedudo.com', // receive the message on your company email + subject: `Message from Bedudo user: ${name}, ${email}`, + text: `${message}`, + }; + + transporter.sendMail(mailData, function (err, info) { + if (err) { + // error possibly occurred due to failed login credentials on the provided Google Account + console.log(err); + res.send(err); + // res.redirect("../error.html"); + } + else { + // success + console.log("Email Sent:", info); + res.redirect("/"); + } + }); +}); + + + + +app.listen(process.env.PORT || 3000, () => console.log("Server running.")); From 50e67f21f6bd48f3d503f1f7175a129337bfab4c Mon Sep 17 00:00:00 2001 From: Yash Kadulkar Date: Thu, 6 Oct 2022 09:20:20 +0530 Subject: [PATCH 2/2] FOrm action on contacts and index --- .gitignore | 2 ++ contacts.html | 2 +- index.html | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7db9f21 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/node_modules +*.env \ No newline at end of file diff --git a/contacts.html b/contacts.html index bd7aa5e..90a9f76 100644 --- a/contacts.html +++ b/contacts.html @@ -44,7 +44,7 @@

How you can reach us

-
+
diff --git a/index.html b/index.html index e6c1e5c..fe8c3d5 100644 --- a/index.html +++ b/index.html @@ -133,7 +133,7 @@

How you can reach us

- +