-
Notifications
You must be signed in to change notification settings - Fork 1
/
smtp.js
37 lines (32 loc) · 1.19 KB
/
smtp.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
function wordwrap(str) {
var m = 80;
var b = "\r\n";
var c = false;
var i, j, l, s, r;
str += '';
if (m < 1) {
return str;
}
for (i = -1, l = (r = str.split(/\r\n|\n|\r/)).length; ++i < l; r[i] += s) {
for(s = r[i], r[i] = ""; s.length > m; r[i] += s.slice(0, j) + ((s = s.slice(j)).length ? b : "")){
j = c == 2 || (j = s.slice(0, m + 1).match(/\S*(\s)?$/))[1] ? m : j.input.length - j[0].length || c == 1 && m || j.input.length + (j = s.slice(m).match(/^\S*/)).input.length;
}
}
return r.join("\n");
}
exports.sendmail = function (from, to, subject, body) {
var connection = process.tcp.createConnection(25);
connection.addListener("connect", function (socket) {
connection.send("helo localhost\r\n");
connection.send("mail from: " + from + "\r\n");
connection.send("rcpt to: " + to + "\r\n");
connection.send("data\r\n");
connection.send("To: " + to + "\r\n");
connection.send("Subject: " + subject + "\r\n");
connection.send("Content-Type: text/html\r\n");
connection.send(wordwrap(body) + "\r\n");
connection.send(".\r\n");
connection.send("quit\r\n");
connection.close();
});
};