Advertisement
Guest User

Untitled

a guest
Apr 14th, 2019
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. const MailListener = require("mail-listener2");
  2. const cheerio = require("cheerio");
  3. const fs = require("async-file");
  4. const moment = require("moment");
  5. const readline = require("readline-sync");
  6. console.log("");
  7. console.log("");
  8.  
  9. const emel = readline.question("Masukan username / email gmail : ");
  10. const password = readline.question("Masukan Password : ");
  11.  
  12. const mailListener = new MailListener({
  13. username: emel,
  14. password: password,
  15. host: "imap.yandex.com",
  16. port: 993, // imap port
  17. tls: true,
  18. connTimeout: 10000, // Default by node-imap
  19. authTimeout: 5000, // Default by node-imap,
  20. debug: null, // Or your custom function with only one incoming argument. Default: null
  21. tlsOptions: { rejectUnauthorized: false },
  22. mailbox: "INBOX", // mailbox to monitor
  23. searchFilter: ["UNSEEN","ALL", ["SUBJECT", "BIGtoken"]], // the search filter being used after an IDLE notification has been retrieved
  24. markSeen: true, // all fetched email willbe marked as seen and not fetched next time
  25. fetchUnreadOnStart: true, // use it only if you want to get all unread email on lib start. Default is `false`,
  26. mailParserOptions: { streamAttachments: true } // options to be passed to mailParser lib.
  27. });
  28.  
  29. mailListener.start(); // start listening
  30.  
  31. // stop listening
  32. //mailListener.stop();
  33.  
  34. // mailListener.on("server:connected", function() {
  35. // console.log("imapConnected");
  36. // });
  37.  
  38. // mailListener.on("server:disconnected", function() {
  39. // console.log("imapDisconnected");
  40. // });
  41.  
  42. mailListener.on("mail", function(mail, seqno, attributes) {
  43. // do something with mail object including attachments
  44.  
  45. const $ = cheerio.load(mail.html);
  46. const src = $(".button").attr("href");
  47. if (src !== undefined && src.length !== 0) {
  48. fs.appendFile("result_yahoo.txt", `${src}\n`, "utf-8");
  49. console.log(
  50. "[" +
  51. " " +
  52. moment().format("HH:mm:ss") +
  53. " " +
  54. "]" +
  55. " " +
  56. "Lokasi Link :" +
  57. " " +
  58. `result.txt`
  59. );
  60. }
  61. // mail processing code goes here
  62. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement