-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8a8269
commit 262cf98
Showing
3 changed files
with
22 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|