Skip to content

Commit

Permalink
🍂Backend: Welcome email for New Subscribers added (#1121)
Browse files Browse the repository at this point in the history
* Upvote and Downvotes fixed

* Welcome email for new subscribers added
  • Loading branch information
BHS-Harish authored Aug 9, 2024
1 parent 0081e4a commit 8129776
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
31 changes: 31 additions & 0 deletions backend/app/routes/subscribers/postSubscriber.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,22 @@ const to = require("await-to-js").default;
const Subscriber = require('../../models/Subscriber');
const { ErrorHandler } = require('../../../helpers/error')
const constants = require('../../../constants');
const nodemailer = require('nodemailer')
const config = require('../../../config')
const { welcomeSubscriberMailTemplate } = require('../../../utility/emailTemplates')

module.exports = async (req, res, next) => {
const transporter = nodemailer.createTransport({
type: 'SMTP',
host: config.EMAIL_HOST,
secure: true,
debug: true,
port: 465,
auth: {
user: config.EMAIL_USER,
pass: config.EMAIL_PASS,
},
});
const [err, response] = await to(Subscriber.create({ ...req.body }));
if (err) {
if (err.code === 11000) {
Expand All @@ -21,6 +35,23 @@ module.exports = async (req, res, next) => {
});
return next(error);
}
const mailOptions = {
from: `HITK TECH Community <${config.EMAIL_USER}>`,
to: req.body.email,
subject: 'Welcome to the HITK TECH Community newsletter 😍',
html: welcomeSubscriberMailTemplate(),
};
await transporter.sendMail(mailOptions).catch((err) => {
if (err) {
const error = new ErrorHandler(constants.ERRORS.UNEXPECTED, {
statusCode: 500,
message: 'The server encountered an unexpected condition which prevented it from fulfilling the request.',
errStack: err,
user: req.body.email,
});
throw error;
}
});
res.status(200).send({
message: 'Subscribed Successfully',
response: response,
Expand Down
16 changes: 15 additions & 1 deletion backend/utility/emailTemplates.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,18 @@ module.exports.resetPasswordMailTemplate = (data) => {
Please ignore this mail If you not request the service
`;
return emailContent;
};
};

module.exports.welcomeSubscriberMailTemplate=()=>{
const emailContent=`
<h2>Hello There, 👋</h2><br/>
Welcome to HITK Tech Community! 💐
<br/><br/>
Thanks for subscribing to our newsletter and joining our community.We're so happy to have you.🤩
<br/><br/>
Bye for now!
<br/>
The HITK Tech Community Team
`
return emailContent
}

0 comments on commit 8129776

Please sign in to comment.