-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
105 lines (93 loc) · 2.52 KB
/
index.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const nodemailer = require('nodemailer');
function erroremail(service, email, pass, toemail=email) {
if(!service||!email||!pass) throw new Error('erroremail: not valid parameters');
const transporter = nodemailer.createTransport({
service: service,
auth: {
user: email,
pass: pass
}
});
return function (err, req, res, next){
const date = new Date();
const content = `
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Erroremail</title>
<style>
body, h1, p {
margin: 0;
padding: 0;
}
body {
font-family: 'Arial', sans-serif;
line-height: 1.5;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: #f4f4f4;
}
h1 {
color: #333;
margin-bottom: 20px;
text-align: center;
}
p {
color: #555;
margin-top: 5px;
}
#error{
border: 2px solid #555;
background-color: azure;
padding: 5px;
border-radius: 5px;
font-family: monospace;
color: black;
box-shadow: 0px 2px 2px #5555556b;
font-size: .875rem;
line-height: 1.125rem;
line-break: anywhere;
white-space: pre-wrap;
overflow: auto;
max-height: 64vh;
}
footer{
margin-top: 5px;
text-align: center;
}
</style>
</head>
<body>
<div class="container">
<h1>Error eMail</h1>
<p>Date: ${date.toString()}</p>
<div id="error">${err.stack.toString()}</div>
<p>Good luck !</p>
<footer>
<a target='_blank' href="https://github.com/GiorgiMakh/erroremail"><img width="32" height="32" src="https://github.githubassets.com/assets/GitHub-Mark-ea2971cee799.png"></img></a>
</footer>
</div>
</body>
</html>
`;
const mailOptions = {
from: 'Error Mail',
to: toemail,
subject: `Error ${err.code}`,
html: content
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
next(error);
} else {
console.log('\x1b[31merror email\x1b[0m sent: ' + info.response);
}
});
}
}
module.exports = erroremail;