diff --git a/backend/.env.example b/backend/.env.example
index 8e23b5b..123e47b 100644
--- a/backend/.env.example
+++ b/backend/.env.example
@@ -8,7 +8,7 @@ SECRET="secret"
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
DATABASE_URL="{DATABASE_URL}"
-BREVO_USER="{}"
-BREVO_PASSWORD="{}"
-BREVO_HOST="{}"
-BREVO_PORT=587
\ No newline at end of file
+SMTP_EMAIL="{}"
+SMTP_PASSWORD="{}"
+SMTP_PORT=587
+SMTP_HOST="{}"
\ No newline at end of file
diff --git a/backend/src/controllers/userControllers.ts b/backend/src/controllers/userControllers.ts
index 4ef70c4..3e4f42b 100644
--- a/backend/src/controllers/userControllers.ts
+++ b/backend/src/controllers/userControllers.ts
@@ -92,7 +92,7 @@ const registerUser = asyncHandler(async (req: Request, res: Response) => {
const url = `https://api-statuscode1.wedevelopers.online/api/user/verify/${token}`;
const htmlContent = `Verify using this link`;
// @ts-ignore
- sendMail();
+ sendMail(htmlContent, email);
res.status(201).json({ message: "User created" });
} else {
const user = await prisma.user.create({
@@ -109,7 +109,7 @@ const registerUser = asyncHandler(async (req: Request, res: Response) => {
const url = `https://api-statuscode1.wedevelopers.online/api/user/verify/${token}`;
const htmlContent = `Verify using this link`;
// @ts-ignore
- await sendMail(email, htmlContent);
+ sendMail(htmlContent, email);
res.status(201).json({ message: "User created" });
}
});
diff --git a/backend/src/mail/sendMail.ts b/backend/src/mail/sendMail.ts
index f190fac..cd2ad68 100644
--- a/backend/src/mail/sendMail.ts
+++ b/backend/src/mail/sendMail.ts
@@ -1,54 +1,29 @@
-// import nodemailer from "nodemailer";
-// import asyncHandler from "express-async-handler";
-// const transporter = nodemailer.createTransport({
-// // @ts-ignore
-// host: process.env.BREVO_HOST,
-// port: process.env.BREVO_PORT,
-// secure: false, // Use `true` for port 465, `false` for all other ports
-// auth: {
-// user: process.env.BREVO_USER,
-// pass: process.env.BREVO_PASSWORD,
-// },
-// });
-
-// const sendMail = asyncHandler(async (email, url) => {
-// await transporter.sendMail({
-// from: '"Review" ',
-// // @ts-ignore
-// to: email,
-// subject: "URL/OTP for verification",
-// text: "Single use URL/OTP",
-// // @ts-ignore
-// html: url,
-// });
-// });
-
-// export default sendMail;
-
import nodemailer from 'nodemailer';
-const sendMail = () => {
- // Step 1: Create a transporter object with SMTP server details
+const sendMail = (htmlContent: any, receiverEmail: string) => {
+ const port = process.env.SMTP_PORT;
+ const host = process.env.SMTP_HOST;
+ const senderEmail = process.env.SMTP_EMAIL;
+ const password = process.env.SMTP_PASSWORD;
let transporter = nodemailer.createTransport({
- host: 'smtp.gmail.com', // Replace with your SMTP server (e.g., smtp.gmail.com for Gmail)
- port: 465, // Use 587 for TLS or 465 for SSL
- secure: true, // Set to true if using port 465 (SSL)
+ // @ts-ignore
+ host: 'smtp.gmail.com',
+ port: port,
+ secure: true,
auth: {
- user: 'somnathchattaraj51@gmail.com', // Your SMTP username (email)
- pass: 'ejqcrhjwectmivcd', // Your SMTP password
+ user: host,
+ pass: password,
},
});
- // Step 2: Define the email options (sender, receiver, subject, and body)
let mailOptions = {
- from: '"Campus-Chatter Admin" campus_chatter@gmail.com', // Sender address
- to: 'somnathc.it.ug@jadavpuruniversity.in', // List of recipients
- subject: 'Hello from Node.js!', // Subject line
- text: 'This is a test email sent using Nodemailer.', // Plain text body
- html: 'This is a test email sent using Nodemailer.', // HTML body (optional)
+ from: `"Campus-Chatter Admin" <${senderEmail}>`,
+ to: receiverEmail,
+ subject: 'OTP Verification',
+ text: htmlContent,
+ html: htmlContent,
};
- // Step 3: Send the email
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log('Error while sending email:', error);