Skip to content

Instantly share code, notes, and snippets.

@asdqwe3124
Created December 7, 2020 10:28
Show Gist options
  • Save asdqwe3124/ec84303241f49a6f3164721508460457 to your computer and use it in GitHub Desktop.
Save asdqwe3124/ec84303241f49a6f3164721508460457 to your computer and use it in GitHub Desktop.
mock-smtp-server.js
const SMTPServer = require("smtp-server").SMTPServer;
const TelegramBot = require('node-telegram-bot-api');
const fetch = require('node-fetch');
const TelegramToken = '';
const bot = new TelegramBot(TelegramToken, {polling: false});
const chatId = '';
const server = new SMTPServer({
onConnect(session, callback) {
// if (session.remoteAddress === "10.10.10.2") {
// return callback(new Error("No connections from localhost allowed"));
// }
console.log("Motion Detected");
bot.sendMessage(chatId, 'Motion Detected');
let url = 'http://IP-CAMERA-IP-ADDRESS/webcapture.jpg?user=USERNAME&password=PASSWORD&command=snap&channel=1';
fetch(url).then((res) => res.buffer()).then(buffer => bot.sendPhoto(chatId, buffer));
return callback(); // Accept the connection
}
});
server.on("error", err => {
console.log("Error %s", err.message);
});
server.listen(25);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment