Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. [Frage] Email Script erweitern

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    [Frage] Email Script erweitern

    This topic has been deleted. Only users with topic management privileges can see it.
    • W
      webseb79 last edited by

      Hallo,
      ich habe aus einem anderen Beitrag ein Script in Verwendung welches meine Email aus meinem Postfach abruft.
      Dort wird aber nur immer die aktuellste Email geholt und überschreibt die letzte im Datenpunkt.
      Wie kann man das Script erweitern und die letzten 4 Emails in separate Datenpunkte schreiben?

      var mailobj = {val:
      
                      {
      
                          from:  "",
      
                          topic: "",
      
                          text: "",
      
                      }
      
                  };
      
      createState("Email.Reception",mailobj);
      
      createState("Email.from_address");
      
      createState("Email.from_name");
      
      createState("Email.mail_subject");
      
      createState("Email.mail_text");
      
              
      
      schedule("*/2 * * * *", function (obj) {
      
          var MailListener = require("mail-listener2");
      
          var mailListener = new MailListener({
      
            username: "blabla.com",    // hier Email Adresse eintragen
      
            password: "geheimespassword",	      // hier Passwort eintragen	
      
            host: "imap.gmail.com",
      
            port: 993, // imap port
      
            tls: true,
      
            connTimeout: 10000, // Default by node-imap
      
            authTimeout: 5000, // Default by node-imap,
      
            debug: null, // Or your custom function with only one incoming argument. Default: null
      
            tlsOptions: { rejectUnauthorized: false },
      
            mailbox: "INBOX", // mailbox to monitor
      
            searchFilter: ["UNSEEN"], // the search filter being used after an IDLE notification has been retrieved
      
            markSeen: true, // all fetched email willbe marked as seen and not fetched next time
      
            fetchUnreadOnStart: true, // use it only if you want to get all unread email on lib start. Default is `false`,
      
            mailParserOptions: {streamAttachments: true}, // options to be passed to mailParser lib.
      
            attachments: false, // download attachments as they are encountered to the project directory
      
            attachmentOptions: { directory: "attachments/" } // specify a download directory for attachments
      
          });
      
       
      
          mailListener.start();
      
          mailListener.on("server:connected", function(){console.log("imapconconnected");});
      
          mailListener.on("server:disconnected", function(){console.log("imapDisconnected");});
      
          mailListener.on("error", function(err){console.log(err);});
      
          mailListener.on("mail", function(mail, seqno, attributes){
      
              log(mail.from[0].address);
      
              log(mail.from[0].name);
      
              log(mail.subject);
      
              log( mail.text);
      
              var mailobj = {val:
      
                      {
      
                          from:  mail.from[0].name,
      
                          topic: mail.subject,
      
                          text:  mail.text
      
                      }
      
                  };
      
              setState("Email.Reception", mailobj);
      
              setState("Email.from_address", mail.from[0].address);
      
              setState("Email.from_name", mail.from[0].name);
      
              setState("Email.mail_subject", mail.subject);
      
              setState("Email.mail_text", mail.text);
      
       
      
          });
      
          mailListener.on("attachment", function(attachment){console.log(attachment.path);});
      
          setTimeout(function(){mailListener.stop();},20000);
      
      });
      

      Danke im voraus und einen schönen Sonntag

      Sebastian

      1 Reply Last reply Reply Quote 0
      • First post
        Last post

      Support us

      ioBroker
      Community Adapters
      Donate

      648
      Online

      31.8k
      Users

      80.0k
      Topics

      1.3m
      Posts

      1
      1
      203
      Loading More Posts
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes
      Reply
      • Reply as topic
      Log in to reply
      Community
      Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
      The ioBroker Community 2014-2023
      logo