Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Emails auswerten, Adapter stürzt ab

    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

    Emails auswerten, Adapter stürzt ab

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

      Ich versuche gerade eine Emailauswertung zu realisieren, dabei habe ich als Anfänger viele kleine Probleme.

      Derzeit habe ich folgenden Code:

      onst Imap = require('imap'); // imap-Modul wird benötigt
      const utf8 = require('utf8'); // utf8-Modul wird benötigt
      
      const imap = new Imap({
          user: 'name@server.de', // E-Mail-Adresse
          password: 'sagichnicht', // Passwort
          host: 'imap.anbieter.de', // IMAP-Server
          port: 993, // Port
          tls: true // TLS verwenden
      });
      
      function openInbox(cb) {
          imap.openBox('INBOX', true, cb);
      }
      
      imap.once('ready', function() {
          openInbox(function(err, box) {
              if (err) throw err;
              imap.search(['UNSEEN'], function(err, results) {
                  if (err) throw err;
                  const f = imap.fetch(results, { bodies: '' });
                  f.on('message', function(msg, seqno) {
                      msg.on('body', function(stream, info) {
                          let buffer = '';
                          stream.on('data', function(chunk) {
                              buffer += chunk.toString('utf8');
                          });
                          stream.once('end', function() {
                              console.log('E-Mail empfangen:', buffer); // Debug-Ausgabe
                              const text = utf8.decode(buffer); // UTF-8 kodierten Text in lesbares Format umwandeln
                              setState('0_userdata.0.Datenpunkt.Alarmtext', text); // In Datenpunkt speichern
                          });
                      });
                      msg.once('end', function() {
                          imap.setFlags(seqno, '\Seen', function(err) { // E-Mail als gelesen markieren
                              if (err) throw err;
                          });
                      });
                  });
                  f.once('error', function(err) {
                      console.log('Fehler beim Abrufen der E-Mail:', err);
                  });
                  f.once('end', function() {
                      imap.end();
                  });
              });
          });
      });
      
      imap.once('error', function(err) {
          console.log('Fehler beim Verbinden mit dem IMAP-Server:', err);
      });
      
      imap.once('end', function() {
          console.log('Verbindung zum IMAP-Server getrennt');
      });
      
      imap.connect(); // Verbindung zum IMAP-Server herstellen
      

      Wenn ich das Script starte wird die letzte Mail abgeholt und in den Datenpunkt geschrieben.
      ABER
      Die Mail wird nicht als gelesen markiert und der javascriptadapter stürzt komplett ab.
      Vermutlich wird der Code daher nicht volständig ausgeführt.

      im LOG finde ich mich nicht zurecht um den Fehler genauer zu identifizieren.

      Schalte ich das script ab, lässt sich der JS Adapter wieder starten und ich könnt die nächste mail abholen.

      Auszug aus dem LOG

      host.raspberrypi
      2023-04-01 17:45:48.824	error	instance system.adapter.javascript.0 terminated with code 1 (JS_CONTROLLER_STOPPED)
      host.raspberrypi
      2023-04-01 17:45:48.824	error	Caught by controller[0]: at processTicksAndRejections (node:internal/process/task_queues:82:21)
      host.raspberrypi
      2023-04-01 17:45:48.823	error	Caught by controller[0]: at emitReadable_ (node:internal/streams/readable:578:12)
      host.raspberrypi
      2023-04-01 17:45:48.823	error	Caught by controller[0]: at TLSSocket.emit (node:domain:489:12)
      host.raspberrypi
      2023-04-01 17:45:48.823	error	Caught by controller[0]: at TLSSocket.emit (node:events:513:28)
      host.raspberrypi
      2023-04-01 17:45:48.823	error	Caught by controller[0]: at TLSSocket.Parser._cbReadable (/opt/iobroker/node_modules/iobroker.javascript/node_modules/imap/lib/Parser.js:53:12)
      host.raspberrypi
      2023-04-01 17:45:48.823	error	Caught by controller[0]: at Parser._tryread (/opt/iobroker/node_modules/iobroker.javascript/node_modules/imap/lib/Parser.js:82:15)
      host.raspberrypi
      2023-04-01 17:45:48.823	error	Caught by controller[0]: at Parser._parse (/opt/iobroker/node_modules/iobroker.javascript/node_modules/imap/lib/Parser.js:139:16)
      host.raspberrypi
      2023-04-01 17:45:48.823	error	Caught by controller[0]: at Parser._resTagged (/opt/iobroker/node_modules/iobroker.javascript/node_modules/imap/lib/Parser.js:175:10)
      host.raspberrypi
      2023-04-01 17:45:48.823	error	Caught by controller[0]: at Parser.emit (node:domain:489:12)
      host.raspberrypi
      2023-04-01 17:45:48.822	error	Caught by controller[0]: at Parser.emit (node:events:513:28)
      host.raspberrypi
      2023-04-01 17:45:48.822	error	Caught by controller[0]: at Parser.<anonymous> (/opt/iobroker/node_modules/iobroker.javascript/node_modules/imap/lib/Connection.js:194:10)
      host.raspberrypi
      2023-04-01 17:45:48.822	error	Caught by controller[0]: at Connection._resTagged (/opt/iobroker/node_modules/iobroker.javascript/node_modules/imap/lib/Connection.js:1502:11)
      host.raspberrypi
      2023-04-01 17:45:48.821	error	Caught by controller[0]: Error: Command not allowed during EXAMINE
      
      javascript.0
      2023-04-01 17:45:48.716	error	Error: Command not allowed during EXAMINE at Connection._resTagged (/opt/iobroker/node_modules/iobroker.javascript/node_modules/imap/lib/Connection.js:1502:11) at Parser.<anonymous> (/opt/iobroker/node_modules/iobroker.javascript/node_modules/imap/lib/Connection.js:194:10) at Parser.emit (node:events:513:28) at Parser.emit (node:domain:489:12) at Parser._resTagged (/opt/iobroker/node_modules/iobroker.javascript/node_modules/imap/lib/Parser.js:175:10) at Parser._parse (/opt/iobroker/node_modules/iobroker.javascript/node_modules/imap/lib/Parser.js:139:16) at Parser._tryread (/opt/iobroker/node_modules/iobroker.javascript/node_modules/imap/lib/Parser.js:82:15) at TLSSocket.Parser._cbReadable (/opt/iobroker/node_modules/iobroker.javascript/node_modules/imap/lib/Parser.js:53:12) at TLSSocket.emit (node:events:513:28) at TLSSocket.emit (node:domain:489:12) at emitReadable_ (node:internal/streams/readable:578:12) at processTicksAndRejections (node:internal/process/task_queues:82:21)
      
      javascript.0
      2023-04-01 17:45:48.716	error	Error: Command not allowed during EXAMINE
      
      javascript.0
      2023-04-01 17:45:48.715	error	An error happened which is most likely from one of your scripts, but the originating script could not be detected.
      

      Was bedeutet Error: Command not allowed during EXAMINE ??

      Oder gibt es eine leichtere Möglichkeit Emails abzufragen??

      M 1 Reply Last reply Reply Quote 0
      • M
        MCU @Moebi last edited by

        @moebi Es gibt einen Adapter imap?
        6f641044-5714-4b44-a94f-7dacba294f68-image.png

        M 1 Reply Last reply Reply Quote 0
        • M
          Moebi @MCU last edited by

          @mcu nicht das ich wüsste.
          Es gibt das npm Modul IMAP welches irgendwie für den Javascript Adapter notwendiges für E-Mail bereitstellen soll...

          DJMarc75 1 Reply Last reply Reply Quote 0
          • DJMarc75
            DJMarc75 @Moebi last edited by

            @moebi https://forum.iobroker.net/topic/63400/test-adapter-iobroker-imap-v0-0-1-github

            Ist zwar noch in der frühen Testphase, läuft aber schon gut.

            1 Reply Last reply Reply Quote 0
            • M
              Moebi last edited by

              @djmarc75 aaah, ich hatte das als Frage verstanden 😅

              Das schaue ich mir mal an!

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

              Support us

              ioBroker
              Community Adapters
              Donate

              676
              Online

              31.8k
              Users

              80.0k
              Topics

              1.3m
              Posts

              3
              5
              208
              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