I am using Brevo (previously Sendinblue) for sending transactional emails like verification, password-reset, etc.
I deployed my NodeJS app on cyclic. All the other functionalities are working fine except the emails.
The emails were working great in the localhost, but as soon as I deployed my app they aren't working anymore. Most probably the problem is with Brevo (previously Sendinblue) according to me. Adding the relevant code below.
sendEmail.js
const nodemailer = require("nodemailer");
const sendEmail = async (email, subject, text) => {
try {
const transporter = nodemailer.createTransport({
service: "SendinBlue",
auth: {
user: process.env.SIB_EMAIL,
pass: process.env.SIB_PASS,
},
});
const mailOptions = {
from: process.env.SIB_EMAIL,
to: email,
subject: subject,
html: text,
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log("Error:", error);
} else {
console.log("Email sent:", info.response);
}
});
} catch (err) {
console.log(err);
}
};
module.exports = sendEmail;
/forgot-password
const forgotPassword = async (req, res) => {
try {
const { email } = req.body;
const user = await User.findOne({ email });
if (!user) {
return res.status(404).json({ success: true, message: "User not found" });
}
const resetToken = uuid();
user.reset_token = resetToken;
user.reset_token_expiry = Date.now() + 3600000; //1 hour
await user.save();
const resetLink = `${process.env.FRONTEND_URI}/reset-password?resetToken=${resetToken}`;
const emailContent = `
<p>Click on the link below to reset your password</p>
<a href=${resetLink}>${resetLink}</a>
<br>
<h5>Team Sukoon</h5>
`;
sendEmail(email, "Sukoon: Reset your password", emailContent);
res.status(200).json({ success: true, message: "Email sent successfully" });
} catch {
res.status(500).json({ success: false, message: "server error" });
}
};
When I check cyclic logs there are no errors and I get a response code 200.