Advertisement
Guest User

Untitled

a guest
Mar 14th, 2019
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. /*
  2. * Email and Free mobile credentials.
  3. */
  4.  
  5. let config = {
  6. free_user: xxxxxxx,
  7. free_password: "XXXXXXX",
  8. username: "xxxxxxxxxxxxxx",
  9. password: "xxxxxxxxxxxxxx",
  10. host: "imap.gmail.com",
  11. port: 993, // imap port
  12. tls: true,
  13. };
  14.  
  15. /*
  16. * !!!!!!!!!!!!!!!!!!!!!!!!!!!
  17. * DO NOT EDIT FOLLOWING LINES, EXCEPT THE MESSAGE AT LINE 66!
  18. * !!!!!!!!!!!!!!!!!!!!!!!!!!!
  19. */
  20.  
  21. var MailListener = require("mail-listener2");
  22. const freemobile = require('freemobile-sms');
  23. const publicIp = require('public-ip');
  24.  
  25. /*
  26. * We make all new messages incoming fetched as read.
  27. */
  28. config = {
  29. ...config,
  30. connTimeout: 10000,
  31. authTimeout: 5000,
  32. debug: console.log,
  33. tlsOptions: { rejectUnauthorized: false },
  34. mailbox: "INBOX",
  35. searchFilter: ["UNSEEN"],
  36. markSeen: true,
  37. fetchUnreadOnStart: false,
  38. mailParserOptions: {streamAttachments: true},
  39. attachments: false,
  40. attachmentOptions: { directory: "attachments/" }
  41. };
  42.  
  43. /*
  44. * For Free Mobile dependency
  45. */
  46. var credentials = {
  47. user: config.free_user,
  48. password: config.free_password
  49. };
  50.  
  51. var mailListener = new MailListener(config);
  52.  
  53. mailListener.start(); // start listening
  54.  
  55. mailListener.on("server:connected", function(){
  56. console.log("imapConnected");
  57. });
  58.  
  59. mailListener.on("mail", async function (mail, seqno, attributes) {
  60. // when a mail is received
  61. console.log("emailParsed", mail);
  62. if (mail.from[0].address === config.username) {
  63. console.log("Alert has been raised!");
  64. var ip = await publicIp.v4(); // we get the public IP address
  65.  
  66. freemobile.send('Alarm. Something weird is happening. Date: \n' + mail.date + '\n Admin interface: ' + ip, credentials)
  67. .then(() => {
  68. console.log("Message sent!");
  69. })
  70. .catch(error => {
  71. console.error('An error has occurred while sending the message.');
  72. });
  73. }
  74. });
  75.  
  76. mailListener.on("error", function(err){
  77.  
  78. });
  79.  
  80. mailListener.on("server:disconnected", function(){
  81. console.log("imapDisconnected");
  82. });
  83.  
  84. mailListener.on("attachment", function(attachment){
  85. console.log(attachment.path);
  86. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement