-
Notifications
You must be signed in to change notification settings - Fork 0
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
18d3dee
commit 6d79d01
Showing
1 changed file
with
43 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import nodemailer from "nodemailer" | ||
|
||
/** | ||
* This fucntion sends an email for verifying when registration | ||
* | ||
* @param {string} email | ||
* @param {string} token | ||
*/ | ||
|
||
export default function sendVerifyMail(email, token){ | ||
try { | ||
// Define email options, including sender, recipient, subject, and message body | ||
const mailOptions = { | ||
from: process.env.EMAIL, | ||
to: email, | ||
subject: 'Password Reset', | ||
text: `You are receiving this because you (or someone else) have requested the reset of the password for your account.\n\n` | ||
+ `Please click on the following link, or paste this into your browser to complete the process:\n\n` | ||
+ `http://localhost:5500/user/reset-password/${token}\n\n` | ||
+ `If you did not request this, please ignore this email and your password will remain unchanged.\n`, | ||
}; | ||
|
||
// Create a transporter for sending emails using nodemailer | ||
const transporter = nodemailer.createTransport({ | ||
service: 'gmail', // Email service provider | ||
auth: { | ||
user: process.env.EMAIL, // Sender's email address | ||
pass: process.env.PASSWORD // Sender's email password | ||
} | ||
}); | ||
|
||
// Send the email using the configured transporter | ||
transporter.sendMail(mailOptions, (err, info) => { | ||
if (err) { | ||
throw new Error("Error during sending email"); | ||
} | ||
|
||
return info.response; | ||
}); | ||
} catch (err) { | ||
throw err; | ||
} | ||
} |