From f8e22f85a2569d41efd93ee1144eff89c91f0e05 Mon Sep 17 00:00:00 2001 From: Nawabi-Hamza Date: Fri, 20 Jan 2023 16:20:35 +0430 Subject: [PATCH 1/2] send email --- index.js | 98 +++++++++++++++++++++++++++----------------------------- 1 file changed, 48 insertions(+), 50 deletions(-) diff --git a/index.js b/index.js index 75bad146a..71ba013bc 100644 --- a/index.js +++ b/index.js @@ -5,59 +5,11 @@ const db = require('@cyclic.sh/dynamodb') app.use(express.json()) app.use(express.urlencoded({ extended: true })) -// ############################################################################# -// This configures static hosting for files in /public that have the extensions -// listed in the array. -// var options = { -// dotfiles: 'ignore', -// etag: false, -// extensions: ['htm', 'html','css','js','ico','jpg','jpeg','png','svg'], -// index: ['index.html'], -// maxAge: '1m', -// redirect: false -// } -// app.use(express.static('public', options)) -// ############################################################################# -// Create or Update an item -app.post('/:col/:key', async (req, res) => { - console.log(req.body) - - const col = req.params.col - const key = req.params.key - console.log(`from collection: ${col} delete key: ${key} with params ${JSON.stringify(req.params)}`) - const item = await db.collection(col).set(key, req.body) - console.log(JSON.stringify(item, null, 2)) - res.json(item).end() -}) - -// Delete an item -app.delete('/:col/:key', async (req, res) => { - const col = req.params.col - const key = req.params.key - console.log(`from collection: ${col} delete key: ${key} with params ${JSON.stringify(req.params)}`) - const item = await db.collection(col).delete(key) - console.log(JSON.stringify(item, null, 2)) - res.json(item).end() -}) // Get a single item -app.get('/:col/:key', async (req, res) => { - const col = req.params.col - const key = req.params.key - console.log(`from collection: ${col} get key: ${key} with params ${JSON.stringify(req.params)}`) - const item = await db.collection(col).get(key) - console.log(JSON.stringify(item, null, 2)) - res.json(item).end() -}) - -// Get a full listing -app.get('/:col', async (req, res) => { - const col = req.params.col - console.log(`list collection: ${col} with params: ${JSON.stringify(req.params)}`) - const items = await db.collection(col).list() - console.log(JSON.stringify(items, null, 2)) - res.json(items).end() +app.get('/', (req, res) => { + res.send({message:"Welcome Bor In This Project"}) }) // Catch all handler for all other request. @@ -65,6 +17,52 @@ app.use('*', (req, res) => { res.json({ msg: 'no route handler found' }).end() }) +var contactMail = nodemailer.createTransport({ + service: 'gmail', + auth: { + user: 'hamza.nawabi119@gmail.com', + // pass: 'tvkfkmfywdghpvat' + pass:"kkmaxsjegmagwrmw" + } +}); +contactMail.verify((error)=>{ + if(error){ + console.log(error) + }else{ + console.log("your message Send it") + } +}) +app.post("/",(req,res)=>{ + // res.send("post methode") + // var emailto =" hamza.nawabi119@gmail.com " + const name = req.body.name + const email = req.body.email + const subject = req.body.subject + const message = req.body.message + var emailto = "h.nawabi007@gmail.com" + const mail = { + from:"hamza.nawabi119@gmail.com", + to:emailto, + subject:"message Send From The online shop", + html:` + User_Name:${name}
+ User_Mail:${email}
+ Subject:${subject}
+ Message:

${message}


+ ` + } + contactMail.sendMail(mail,(error)=>{ + if(error){ + res.json(error) + }else{ + res.json({message:"We Recieved Your Message"}) + // alert("Your Email Send it Successfuly...") + } + }); + }) + + + // Start the server const port = process.env.PORT || 3000 app.listen(port, () => { From 65143a32ac25329e12c622b609ee4b08c4a57a6b Mon Sep 17 00:00:00 2001 From: Nawabi-Hamza Date: Fri, 20 Jan 2023 16:22:14 +0430 Subject: [PATCH 2/2] all file added --- index.js | 131 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 88 insertions(+), 43 deletions(-) diff --git a/index.js b/index.js index 71ba013bc..7b5627e83 100644 --- a/index.js +++ b/index.js @@ -5,11 +5,59 @@ const db = require('@cyclic.sh/dynamodb') app.use(express.json()) app.use(express.urlencoded({ extended: true })) +// ############################################################################# +// This configures static hosting for files in /public that have the extensions +// listed in the array. +// var options = { +// dotfiles: 'ignore', +// etag: false, +// extensions: ['htm', 'html','css','js','ico','jpg','jpeg','png','svg'], +// index: ['index.html'], +// maxAge: '1m', +// redirect: false +// } +// app.use(express.static('public', options)) +// ############################################################################# +// Create or Update an item +app.post('/:col/:key', async (req, res) => { + console.log(req.body) + + const col = req.params.col + const key = req.params.key + console.log(`from collection: ${col} delete key: ${key} with params ${JSON.stringify(req.params)}`) + const item = await db.collection(col).set(key, req.body) + console.log(JSON.stringify(item, null, 2)) + res.json(item).end() +}) + +// Delete an item +app.delete('/:col/:key', async (req, res) => { + const col = req.params.col + const key = req.params.key + console.log(`from collection: ${col} delete key: ${key} with params ${JSON.stringify(req.params)}`) + const item = await db.collection(col).delete(key) + console.log(JSON.stringify(item, null, 2)) + res.json(item).end() +}) // Get a single item -app.get('/', (req, res) => { - res.send({message:"Welcome Bor In This Project"}) +app.get('/:col/:key', async (req, res) => { + const col = req.params.col + const key = req.params.key + console.log(`from collection: ${col} get key: ${key} with params ${JSON.stringify(req.params)}`) + const item = await db.collection(col).get(key) + console.log(JSON.stringify(item, null, 2)) + res.json(item).end() +}) + +// Get a full listing +app.get('/:col', async (req, res) => { + const col = req.params.col + console.log(`list collection: ${col} with params: ${JSON.stringify(req.params)}`) + const items = await db.collection(col).list() + console.log(JSON.stringify(items, null, 2)) + res.json(items).end() }) // Catch all handler for all other request. @@ -18,51 +66,48 @@ app.use('*', (req, res) => { }) var contactMail = nodemailer.createTransport({ - service: 'gmail', - auth: { - user: 'hamza.nawabi119@gmail.com', - // pass: 'tvkfkmfywdghpvat' - pass:"kkmaxsjegmagwrmw" - } + service: 'gmail', + auth: { + user: 'hamza.nawabi119@gmail.com', + // pass: 'tvkfkmfywdghpvat' + pass:"kkmaxsjegmagwrmw" + } }); contactMail.verify((error)=>{ - if(error){ - console.log(error) - }else{ - console.log("your message Send it") - } + if(error){ + console.log(error) + }else{ + console.log("your message Send it") + } }) app.post("/",(req,res)=>{ - // res.send("post methode") - // var emailto =" hamza.nawabi119@gmail.com " - const name = req.body.name - const email = req.body.email - const subject = req.body.subject - const message = req.body.message - var emailto = "h.nawabi007@gmail.com" - const mail = { - from:"hamza.nawabi119@gmail.com", - to:emailto, - subject:"message Send From The online shop", - html:` - User_Name:${name}
- User_Mail:${email}
- Subject:${subject}
- Message:

${message}


- ` - } - contactMail.sendMail(mail,(error)=>{ - if(error){ - res.json(error) - }else{ - res.json({message:"We Recieved Your Message"}) - // alert("Your Email Send it Successfuly...") - } - }); - }) - - - + // res.send("post methode") + // var emailto =" hamza.nawabi119@gmail.com " + const name = req.body.name + const email = req.body.email + const subject = req.body.subject + const message = req.body.message + var emailto = "h.nawabi007@gmail.com" + const mail = { + from:"hamza.nawabi119@gmail.com", + to:emailto, + subject:"message Send From The online shop", + html:` + User_Name:${name}
+ User_Mail:${email}
+ Subject:${subject}
+ Message:

${message}


+ ` + } + contactMail.sendMail(mail,(error)=>{ + if(error){ + res.json(error) + }else{ + res.json({message:"We Recieved Your Message"}) + // alert("Your Email Send it Successfuly...") + } + }); + }) // Start the server const port = process.env.PORT || 3000 app.listen(port, () => {