adrianhajdin / pricewise

Dive into web scraping and build a Next.js 13 eCommerce price tracker within a single video that teaches you data scraping, cron jobs, sending emails, deployment, and more.
https://pricewise-jsm.vercel.app
508 stars 151 forks source link

Regarding mails of price drop. #12

Closed sathyashiva9 closed 2 weeks ago

sathyashiva9 commented 8 months ago

It's sending welcome message when added a new product to track but it is not sending any price drop messages when the price goes below the lowest price. I have even tried by taking lowest price more than the current price. But still it is not sending mails.

HRIDYANSHU054 commented 1 month ago

@sathyashiva9 were you able to resolve this?

sathyashiva9 commented 2 weeks ago

@sathyashiva9 were you able to resolve this?

Yes it worked for me, we need to return a promise in the send email function.


export const sendEmail = async (emailContent: EmailContent, sendTo: string[]) => {
return new Promise((resolve, reject) => {
const mailOptions = {
from: 'javascriptmastery@outlook.com',
to: sendTo,
html: emailContent.body,
subject: emailContent.subject,
};

transporter.sendMail(mailOptions, (error: any, info: any) => {
if (error) {
console.log(error);
reject(error);
} else {
console.log('Email sent: ', info);
resolve(info);
}
});
});
}