forked from anuragverma108/SwapReads
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
e5372a4
commit d27c2fb
Showing
7 changed files
with
113 additions
and
60 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
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
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,41 @@ | ||
'use strict'; | ||
const nodemailer=require('nodemailer'); | ||
require('dotenv').config(); | ||
|
||
const transporter=nodemailer.createTransport({ | ||
service:'gmail', | ||
host:'smtp.gmail.com', | ||
port:587, | ||
secure:false, | ||
auth:{ | ||
user:"[email protected]", | ||
pass:process.env.APP_PASSWORD | ||
} | ||
}) | ||
|
||
const mailOptions={ | ||
from:{ | ||
name:'SwapReads', | ||
address:"[email protected]" | ||
}, | ||
to:"[email protected]", | ||
subject:'Welcome to Our Newsletter!', | ||
text:"Hello, Thank you for subscribing to our newsletter! Stay tuned for exciting updates.", | ||
} | ||
|
||
|
||
const sendMail=async(transporter,mailOptions)=>{ | ||
try{ | ||
await transporter.sendMail(mailOptions); | ||
console.log('Email sent successfully'); | ||
} | ||
catch(error){ | ||
console.error('Error sending email:',error); | ||
} | ||
} | ||
|
||
const subscribeBtn=document.querySelector('.subscribe-btn'); | ||
subscribeBtn.addEventListener('click',sendMail(transporter,mailOptions)); | ||
|
||
// add event on send message button | ||
const sendMessageBtn = document.getElementById('sendMessageBtn'); | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -90,49 +90,4 @@ dbConnect().then(() => { | |
res.json({ success: false, message: "Internal Server Error" }); | ||
}); | ||
}); | ||
|
||
// Configure Nodemailer transporter | ||
const transporter = nodemailer.createTransport({ | ||
service: "gmail", | ||
auth: { | ||
user: "[email protected]", | ||
pass: "password", | ||
}, | ||
}); | ||
|
||
function sendBuyingEmailToSeller(sellerEmail, bookTitle, bookPrice, bookAuthor, buyerEmail) { | ||
const mailOptions = { | ||
from: "[email protected]", | ||
to: sellerEmail, | ||
subject: "Someone is interested in your book!", | ||
text: `Congratulations! Your book "${bookTitle}" by ${bookAuthor} at ${bookPrice} has a Buyer ${buyerEmail}.`, | ||
}; | ||
|
||
transporter.sendMail(mailOptions, (err, info) => { | ||
if (err) { | ||
console.error("Error sending email:", err); | ||
} else { | ||
console.log("Email sent:", info.response); | ||
} | ||
}); | ||
} | ||
|
||
function sendListingEmailToSeller(sellerEmail, bookTitle) { | ||
const mailOptions = { | ||
from: "[email protected]", | ||
to: sellerEmail, | ||
subject: "Your book listing is live!", | ||
text: `Congratulations! Your book "${bookTitle}" is now listed for sale.`, | ||
}; | ||
|
||
transporter.sendMail(mailOptions, (err, info) => { | ||
if (err) { | ||
console.error("Error sending email:", err); | ||
} else { | ||
console.log("Email sent:", info.response); | ||
} | ||
}); | ||
} | ||
|
||
app.listen(3000, () => console.log("Server is running on port 3000")); | ||
}); | ||
}); |