Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Email and Free mobile credentials.
- */
- let config = {
- free_user: xxxxxxx,
- free_password: "XXXXXXX",
- username: "xxxxxxxxxxxxxx",
- password: "xxxxxxxxxxxxxx",
- host: "imap.gmail.com",
- port: 993, // imap port
- tls: true,
- };
- /*
- * !!!!!!!!!!!!!!!!!!!!!!!!!!!
- * DO NOT EDIT FOLLOWING LINES, EXCEPT THE MESSAGE AT LINE 66!
- * !!!!!!!!!!!!!!!!!!!!!!!!!!!
- */
- var MailListener = require("mail-listener2");
- const freemobile = require('freemobile-sms');
- const publicIp = require('public-ip');
- /*
- * We make all new messages incoming fetched as read.
- */
- config = {
- ...config,
- connTimeout: 10000,
- authTimeout: 5000,
- debug: console.log,
- tlsOptions: { rejectUnauthorized: false },
- mailbox: "INBOX",
- searchFilter: ["UNSEEN"],
- markSeen: true,
- fetchUnreadOnStart: false,
- mailParserOptions: {streamAttachments: true},
- attachments: false,
- attachmentOptions: { directory: "attachments/" }
- };
- /*
- * For Free Mobile dependency
- */
- var credentials = {
- user: config.free_user,
- password: config.free_password
- };
- var mailListener = new MailListener(config);
- mailListener.start(); // start listening
- mailListener.on("server:connected", function(){
- console.log("imapConnected");
- });
- mailListener.on("mail", async function (mail, seqno, attributes) {
- // when a mail is received
- console.log("emailParsed", mail);
- if (mail.from[0].address === config.username) {
- console.log("Alert has been raised!");
- var ip = await publicIp.v4(); // we get the public IP address
- freemobile.send('Alarm. Something weird is happening. Date: \n' + mail.date + '\n Admin interface: ' + ip, credentials)
- .then(() => {
- console.log("Message sent!");
- })
- .catch(error => {
- console.error('An error has occurred while sending the message.');
- });
- }
- });
- mailListener.on("error", function(err){
- });
- mailListener.on("server:disconnected", function(){
- console.log("imapDisconnected");
- });
- mailListener.on("attachment", function(attachment){
- console.log(attachment.path);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement