forked from devamdoshi212/Sports-Infrastructure-Management
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendEmail.js
58 lines (48 loc) · 1.55 KB
/
sendEmail.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const nodemailer = require("nodemailer");
const crypto = require("crypto");
module.exports.passwordGenerate = function (length) {
const charset =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*";
let password = "";
for (let i = 0; i < length; i++) {
const randomIndex = crypto.randomInt(0, charset.length);
password += charset.charAt(randomIndex);
}
return password;
};
// const password = generateRandomPassword(8);
// Create a transporter object using the default SMTP transport
module.exports.sendEmail = function (email, password) {
const transporter = nodemailer.createTransport({
service: "Gmail", // Use your email service provider here
auth: {
user: "[email protected]", // Your email address
pass: "bypqzlyujtzqvcxx", // Your email password or application-specific password
},
});
const emailContent = `
<html>
<body>
<p><strong>Dear Authority,</strong></p>
<p>This is an email from the admin. Your new password is:</p>
<p style="font-size: 24px; color: #0077FF;">${password}</p>
</body>
</html>
`;
console.log("Email in mailoption" + email);
// Define email data
const mailOptions = {
from: "[email protected]",
to: email, // Recipient's email address
subject: "Hello from Node.js",
html: emailContent,
};
// Send the email
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.error("Error:", error);
} else {
console.log("Email sent:", info.response);
}
});
};