-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
71 lines (60 loc) · 1.69 KB
/
server.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
59
60
61
62
63
64
65
66
67
68
69
70
71
const express = require('express');
const nodemailer = require('nodemailer');
const app = express();
const port = 3000;
let intervalId;
app.use(express.json());
// Configure Nodemailer with your email service credentials
const transporter = nodemailer.createTransport({
service: 'your_email_service', // e.g., 'gmail'
auth: {
user: 'your_email_address', //put ur email
pass: 'your_email_password', //put ur pwd
},
});
// Send email
function sendEmail(toEmail) {
const mailOptions = {
from: 'abc@gmail.com',
to: toEmail,
subject: 'LogBot 2.0 attachment',
text: 'Your message',
attachments: [
{
filename: 'Record.txt',
content: 'Attachment content',
},
],
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log('Error sending email:', error);
} else {
console.log('Email sent:', info.response);
}
});
}
// Start sending emails periodically
function startSendingEmails(email, timePeriod) {
intervalId = setInterval(() => {
sendEmail(email);
}, timePeriod * 60 * 60 * 1000);
console.log(`Email sending started every ${timePeriod} hour(s).`);
}
// Stop sending emails
function stopSendingEmails() {
clearInterval(intervalId);
console.log('Email sending stopped.');
}
app.post('/start', (req, res) => {
const { email, timePeriod } = req.body;
startSendingEmails(email, timePeriod);
res.send('Email sending started.');
});
app.post('/stop', (req, res) => {
stopSendingEmails();
res.send('Email sending stopped.');
});
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});