-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.js
83 lines (74 loc) · 3.02 KB
/
mail.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
var fs = require('fs');
const https = require('https');
const {SMTPServer} = require('smtp-server');
const parser = require("mailparser").simpleParser
const { Telegraf } = require('telegraf')
const BOT_TOKEN = 'SEU TOKEN';
const chatId = 'SEU TELEGRAM CHAT ID'; //id do canal
const app = new Telegraf(BOT_TOKEN);
console.log('Sistema Iniciado!')
app.telegram.sendMessage(chatId, 'BOT INICIADO!');
const server = new SMTPServer({
disabledCommands: ['STARTTLS'],
authMethods: ['PLAIN', 'LOGIN', 'CRAM-MD5'],
logger: false,
onAuth(auth, session, callback) {
let username = 'santiago';
let password = 'santiago';
if (
auth.username === username &&
(auth.method === 'CRAM-MD5'
? auth.validatePassword(password)
: auth.password === password)
) {
return callback(null, {
user: 'userdata'
});
}
return callback(new Error('Falha ao autenticar'));
},
onData(stream, session, callback){
parser(stream, {}, (err, parsed) => {
function myFunction(item) {
fs.writeFile('img/'+item.filename, item.content, (err) => {
if (err)
console.log(err);
else {
console.log("Arquivo "+item.filename+" salvo\n");
//console.log("Erro ao salvar imagem");
app.telegram.sendPhoto(chatId, { source: 'img/'+item.filename }).then(function(data){
console.log(data);
fs.unlink('img/'+item.filename, (err) => {
if (err) {
console.error(err)
return
}
//file removed
})
});
}
});
//app.telegram.sendPhoto(chatId, { source: 'img/'+item.filename })
}
if (err)
console.log("Error:" , err)
//console.log(parsed)
console.log(parsed)
//let img = encodeURI(parsed.attachments);
let fix = encodeURI(parsed.text);
if(parsed.attachments.length > 0){
parsed.attachments.forEach(myFunction)
let envia = app.telegram.sendMessage(chatId, parsed.text);
console.log(envia);
}else{
let envia = app.telegram.sendMessage(chatId, parsed.text);
console.log(envia);
}
console.log('DEBUG::: '+parsed.subject)
stream.on("end", callback)
})
stream.pipe(process.stdout); // print message to console
stream.on('end', callback);
},
});
server.listen(587, 'SEUIP');