-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from UjjwalSaini07/BackendMailDeploy
Backend mail deploy
- Loading branch information
Showing
10 changed files
with
521 additions
and
12 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.vercel | ||
.env |
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 |
---|---|---|
@@ -0,0 +1,124 @@ | ||
const express = require('express'); | ||
const nodemailer = require('nodemailer'); | ||
const cors = require('cors'); | ||
const bodyParser = require('body-parser'); | ||
require("dotenv").config() | ||
|
||
const app = express(); | ||
const PORT = 5000; // You can change the port if needed | ||
|
||
app.use(cors()); | ||
app.use(bodyParser.json()); | ||
|
||
// Set up Nodemailer transporter | ||
const transporter = nodemailer.createTransport({ | ||
service: 'gmail', // You can use another service like SendGrid or SMTP | ||
auth: { | ||
user: process.env.EMAIL_USER, | ||
pass: process.env.EMAIL_PASS, | ||
}, | ||
}); | ||
|
||
// GET route for /send-email to avoid "Cannot GET" error in the browser | ||
app.get('/send-email', (req, res) => { | ||
res.send('Email API is running. Use POST /send-email to send an email.'); | ||
}); | ||
|
||
// Email sending endpoint | ||
app.post('/send-email', (req, res) => { | ||
const { email } = req.body; | ||
|
||
if (!email) { | ||
return res.status(400).json({ success: false, message: 'Email is required' }); | ||
} | ||
|
||
const mailOptions = { | ||
from: 'saini.ujjwals007@gmail.com', // Your email | ||
to: email, | ||
subject: 'Congratulations! You’ve Successfully Subscribed to Daily Bhagavad Gita Shlokas!', | ||
text: `You have successfully subscribed to daily Bhagavad Gita Shlokas! Congratulations! 🎉 | ||
Get ready to dive deep into the profound wisdom and teachings of the Bhagavad Gita. Each day, you will receive a meaningful Shloka delivered straight to your inbox. These sacred verses will guide you on a spiritual journey, offering insights into life, duty, and inner peace. | ||
Enjoy the daily dose of timeless philosophy and find inspiration from the divine teachings of Lord Krishna. 🌿 | ||
We are excited to have you with us on this path of spiritual growth!` | ||
}; | ||
|
||
transporter.sendMail(mailOptions, (error, info) => { | ||
if (error) { | ||
console.error('Error sending email:', error); | ||
return res.status(500).json({ success: false, message: 'Failed to send email' }); | ||
} | ||
console.log('Email sent:', info.response); | ||
res.status(200).json({ success: true, message: 'Email sent successfully!' }); | ||
}); | ||
}); | ||
|
||
// Start the server | ||
app.listen(PORT, () => { | ||
console.log(`Server is running on http://localhost:${PORT}`); | ||
}); | ||
|
||
export default app; | ||
|
||
|
||
// TOdo: Basic Code with only post request not having Get Request | ||
// const express = require('express'); | ||
// const nodemailer = require('nodemailer'); | ||
// const cors = require('cors'); | ||
// const bodyParser = require('body-parser'); | ||
|
||
// const app = express(); | ||
// const PORT = 5000; // You can change the port if needed | ||
|
||
// app.use(cors()); | ||
// app.use(bodyParser.json()); | ||
|
||
// // Set up Nodemailer transporter | ||
// const transporter = nodemailer.createTransport({ | ||
// service: 'gmail', // You can use another service like SendGrid or SMTP | ||
// auth: { | ||
// user: 'saini.ujjwals007@gmail.com', | ||
// pass: 'pnot bnpc cfwp wnyx', | ||
// }, | ||
// }); | ||
|
||
// // Email sending endpoint | ||
// app.post('/send-email', (req, res) => { | ||
// const { email } = req.body; | ||
|
||
// // const mailOptions = { | ||
// // from: 'saini.ujjwals007@gmail.com', // Your email | ||
// // to: email, | ||
// // // subject: 'Subscription Confirmation', | ||
// // text: '', | ||
// // }; | ||
|
||
// const mailOptions = { | ||
// from: 'saini.ujjwals007@gmail.com', // Your email | ||
// to: email, | ||
// subject: 'Congratulations! You’ve Successfully Subscribed to Daily Bhagavad Gita Shlokas!', | ||
// text: `You have successfully subscribed to daily Bhagavad Gita Shlokas! Congratulations! 🎉 | ||
|
||
// Get ready to dive deep into the profound wisdom and teachings of the Bhagavad Gita. Each day, you will receive a meaningful Shloka delivered straight to your inbox. These sacred verses will guide you on a spiritual journey, offering insights into life, duty, and inner peace. | ||
|
||
// Enjoy the daily dose of timeless philosophy and find inspiration from the divine teachings of Lord Krishna. 🌿 | ||
|
||
// We are excited to have you with us on this path of spiritual growth!` | ||
// }; | ||
|
||
// transporter.sendMail(mailOptions, (error, info) => { | ||
// if (error) { | ||
// console.error('Error sending email:', error); | ||
// return res.status(500).json({ success: false, message: 'Failed to send email' }); | ||
// } | ||
// res.status(200).json({ success: true, message: 'Email sent successfully!' }); | ||
// }); | ||
// }); | ||
|
||
// // Start the server | ||
// app.listen(PORT, () => { | ||
// console.log(`Server is running on http://localhost:${PORT}`); | ||
// }); | ||
|
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,15 @@ | ||
{ | ||
"version": 2, | ||
"builds": [ | ||
{ | ||
"src": "server.js", | ||
"use": "@vercel/node" | ||
} | ||
], | ||
"routes": [ | ||
{ | ||
"src": "/(.*)", | ||
"dest": "/server.js" | ||
} | ||
] | ||
} |
Oops, something went wrong.