Skip to content

Commit

Permalink
Update smptp server details
Browse files Browse the repository at this point in the history
  • Loading branch information
Somnath-Chattaraj committed Oct 1, 2024
1 parent d8a8269 commit 262cf98
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 47 deletions.
8 changes: 4 additions & 4 deletions backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
SMTP_EMAIL="{}"
SMTP_PASSWORD="{}"
SMTP_PORT=587
SMTP_HOST="{}"
4 changes: 2 additions & 2 deletions backend/src/controllers/userControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<a href="${url}">Verify using this link</a>`;
// @ts-ignore
sendMail();
sendMail(htmlContent, email);
res.status(201).json({ message: "User created" });
} else {
const user = await prisma.user.create({
Expand All @@ -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 = `<a href="${url}">Verify using this link</a>`;
// @ts-ignore
await sendMail(email, htmlContent);
sendMail(htmlContent, email);
res.status(201).json({ message: "User created" });
}
});
Expand Down
57 changes: 16 additions & 41 deletions backend/src/mail/sendMail.ts
Original file line number Diff line number Diff line change
@@ -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" <[email protected]>',
// // @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: '[email protected]', // 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" [email protected]', // Sender address
to: '[email protected]', // List of recipients
subject: 'Hello from Node.js!', // Subject line
text: 'This is a test email sent using Nodemailer.', // Plain text body
html: '<b>This is a test email sent using Nodemailer.</b>', // 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);
Expand Down

0 comments on commit 262cf98

Please sign in to comment.