Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. ioBroker Allgemein
    4. Javascript Instanz wird von MailListener getötet

    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

    Javascript Instanz wird von MailListener getötet

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

      Hallo, bei manchen E-Mails bring der Mail Listener die gesamte Javaskript Instanz zum Absturz.
      Den Code habe ich eigentlich 1:1 von der github Seite übernommen.

      Folgendes steht im Logfile:

      TypeError: mime.extension is not a function at MailParser._generateFileName (/opt/iobroker/node_modules/iobroker.javascript/node_modules/mailparser/lib/mailparser.js:1407:27) at MailParser._processStateHeader (/opt/iobroker/node_modules/iobroker.javascript/node_modules/mailparser/lib/mailparser.js:309:61) at MailParser._process (/opt/iobroker/node_modules/iobroker.javascript/node_modules/mailparser/lib/mailparser.js:227:22) at processImmediate (internal/timers.js:464:21)
      error	Error: mime.extension is not a function
      error	An error happened which is most likely from one of your scripts, but the originating script could not be detected.
      

      Das Skript dass meine Mails überwachen soll besteht bisher nur aus:

      var MailListener = require("mail-listener2");
      
      var mailobj = {val:
                      {
                          from:  "",
                          topic: "",
                          text: "",
                      }
                  };
      
      var mailListener = new MailListener({ 
        username: "xxxxxxxxxx",
        password: "xxxxx",
        host: "imap.1und1.de",
        port: 993, // imap port 
        tls: true,
        connTimeout: 10000, // Default by node-imap
        authTimeout: 5000, // Default by node-imap,
        debug: console.log, // Or your custom function with only one incoming argument. Default: null
        tlsOptions: { rejectUnauthorized: false },
        mailbox: "Inbox", // mailbox to monitor
        searchFilter: ["*"], //;["UNSEEN", "FLAGGED"], // 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: true, // download attachments as they are encountered to the project directory
        attachmentOptions: { directory: "attachments/" } // specify a download directory for attachments
      });
      
      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);
          });
      
      

      Was läuft hier schief?

      mickym F 2 Replies Last reply Reply Quote 0
      • mickym
        mickym Most Active @WolfgangFB last edited by

        @wolfgangfb Kill den Mörder. 😉

        1 Reply Last reply Reply Quote 0
        • F
          fastfoot @WolfgangFB last edited by

          @wolfgangfb ich habe const MailListener = require("mail-listener2-updated") verwendet und das funktioniert mit gmail. In deinem code fehlt noch mailListener.start()

          Evtl solltest du auch mal die Attachements abschalten. Unbedingt muss ins Skript das hier rein, sonst hört der auch bei Stop des Skripts nicht auf 🙂

          onStop(() => {
              mailListener.stop();
          })
          
          W 1 Reply Last reply Reply Quote 0
          • W
            WolfgangFB @fastfoot last edited by

            @fastfoot
            Die Zeile mailListener.start() ist ei copy&paste verloren gegangen. Ich habe das jetzt mal probiert, mal sehen ob es hilf.

            F 1 Reply Last reply Reply Quote 0
            • F
              fastfoot @WolfgangFB last edited by

              @wolfgangfb Diese Zeile war aber nicht für den Fehler verantwortlich. Deshalb besser die Nachfolgeversion installieren. Ob er generell connected solltest du sofort nach dem Start sehen, selbst wenn keine neue Mail da ist

              W 1 Reply Last reply Reply Quote 0
              • W
                WolfgangFB @fastfoot last edited by

                @fastfoot

                Das Problem taucht immer noch auf

                TypeError: mime.extension is not a function at MailParser._generateFileName (/opt/iobroker/node_modules/iobroker.javascript/node_modules/mailparser/lib/mailparser.js:1407:27) at MailParser._processStateHeader (/opt/iobroker/node_modules/iobroker.javascript/node_modules/mailparser/lib/mailparser.js:309:61) at MailParser._process (/opt/iobroker/node_modules/iobroker.javascript/node_modules/mailparser/lib/mailparser.js:227:22) at processImmediate (internal/timers.js:464:21)
                

                Kann es sein,. dass es sich um Anhänge handelt, die das Problem auslösen?
                Ich habe aber den Part mit

                mailListener.on("attachment"
                

                schon rausgenommen. Kann man dem Maillistener irgendwie beibringen, Anhänge zu ignorieren?

                F 1 Reply Last reply Reply Quote 0
                • F
                  fastfoot @WolfgangFB last edited by

                  @wolfgangfb

                    mailParserOptions: {streamAttachments: true}, // options to be passed to mailParser lib.
                    attachments: true, // download attachments as they are encountered to the project directory
                    attachmentOptions: { directory: "attachments/" } // specify a download directory for attachments
                  
                  1 Reply Last reply Reply Quote 0
                  • W
                    WolfgangFB last edited by

                    @fastfoot
                    Ich konnte jetzt zu 100% nachvollziehen, dass die gesamte Javascript Instanz abstürzt, sobald die letzte Mail einen Anhang enthält.
                    Ich habe inzwischen

                    var MailListener = require("mail-listener2-updated");
                    

                    und

                      mailParserOptions: {streamAttachments: false}, // options to be passed to mailParser lib.
                      attachments: false, // download attachments as they are encountered to the project directory
                      attachmentOptions: { directory: AttachmentsDirectory } // specify a download directory for attachments
                    

                    gesetzt.
                    Der Trigger

                    mailListener.on("mail", function(mail, seqno, attributes){
                    

                    wird bis zum Ende durchlaufen (mit Logdatei kontrolliert). Dann kommt kein weiterer Logeintrag und die Javascript Instanz stürzt ab, Nach ca. 40 Sekunden startet die Javascript Instanz neu, demnach auch das Skript und das ganze geht in eine Endlosschleife.
                    Hat noch jemand eine Ahnung, wie ich das abstellen könnte?
                    Es wäre ja schon hilfreich, wenn on("mail") wirklich nur aufgerufen werden würde, wenn wirklich eine neue Mail kommt und nicht bei jedem Skriptstart die letzte Mail wieder gelesen werden würde.
                    Welche Alternativen gibt es zu mail-listener2? Ich brauche eigentlich nur den Betreff und den Absender. Der Rest ist für diese Aufgabe irrelevant.

                    DJMarc75 F 2 Replies Last reply Reply Quote 0
                    • DJMarc75
                      DJMarc75 @WolfgangFB last edited by

                      @wolfgangfb sagte in Javascript Instanz wird von MailListener getötet:

                      Welche Alternativen gibt es zu mail-listener2? Ich brauche eigentlich nur den Betreff und den Absender. Der Rest ist für diese Aufgabe irrelevant.

                      Da ich ein ähnliches Problem hatte habe ich das per NODE-RED gelöst - läuft und ich schreibe mir alle Werte einzeln in ein JSON damit.

                      1 Reply Last reply Reply Quote 0
                      • F
                        fastfoot @WolfgangFB last edited by

                        @wolfgangfb sagte in Javascript Instanz wird von MailListener getötet:

                        attachmentOptions: { directory: AttachmentsDirectory }

                        hast markSeen auf false gesetzt?
                        Stimmt dein attachmentOptions: { directory: AttachmentsDirectory }?

                        Ansonsten ist das Programm halt schon recht betagt. Mehr fällt mir dazu nicht ein

                        W 1 Reply Last reply Reply Quote 0
                        • W
                          WolfgangFB @fastfoot last edited by

                          @fastfoot
                          MarkSeen hat das ganze etwas verbessert.
                          Gibt es denn Alternativen um Mails zu empfangen?

                          DJMarc75 F 2 Replies Last reply Reply Quote 0
                          • DJMarc75
                            DJMarc75 @WolfgangFB last edited by

                            @wolfgangfb sagte in Javascript Instanz wird von MailListener getötet:

                            Gibt es denn Alternativen um Mails zu empfangen?

                            Ähm... ignoriert ?

                            @djmarc75 sagte in Javascript Instanz wird von MailListener getötet:

                            Da ich ein ähnliches Problem hatte habe ich das per NODE-RED gelöst - läuft und ich schreibe mir alle Werte einzeln in ein JSON damit.

                            1 Reply Last reply Reply Quote 0
                            • F
                              fastfoot @WolfgangFB last edited by

                              @wolfgangfb sagte in Javascript Instanz wird von MailListener getötet:

                              Gibt es denn Alternativen um Mails zu empfangen?

                              schau dir mal node-imap an, das ist recht aktuell

                              1 Reply Last reply Reply Quote 0
                              • F
                                fastfoot last edited by

                                Hier mal ein Beispiel mit node-imap:

                                /*
                                 * Zweck:     liest emails von Imap Providern
                                 * Datum:     07.07.2022
                                 * Autor:     @fastfoot
                                 *            für iobroker modifizierter Beispielcode von https://github.com/mscdex/node-imap
                                */
                                var Imap = require('imap'),
                                    inspect = require('util').inspect;
                                
                                var imap = new Imap({
                                    user: 'user@gmail.com',
                                    password: 'mypassword',
                                    host: 'imap.gmail.com',
                                    port: 993,
                                    tls: true,
                                    tlsOptions: { rejectUnauthorized: false }, //verhindert den Fehler 'self signed certificate'
                                    debug: console.log // oder null 
                                });
                                
                                function openInbox(cb) {
                                    imap.openBox('INBOX', true, cb);
                                }
                                
                                imap.once('ready', function () {
                                    openInbox(function (err, box) {
                                        if (err) throw err;
                                        var f = imap.seq.fetch('1:5', {
                                            bodies: 'HEADER.FIELDS (FROM TO SUBJECT DATE)',
                                            struct: true
                                        });
                                        f.on('message', function (msg, seqno) {
                                            console.log('Message #' + seqno);
                                            var prefix = '(#' + seqno + ') ';
                                            msg.on('body', function (stream, info) {
                                                var buffer = '';
                                                stream.on('data', function (chunk) {
                                                    buffer += chunk.toString('utf8');
                                                });
                                                stream.once('end', function () {
                                                    const headers = Imap.parseHeader(buffer);
                                                    log('Datum: ' + headers.date[0]);
                                                    log('From: ' + headers.from[0]);
                                                    log('To: ' + headers.to[0]);
                                                    log('Subject: ' + headers.subject[0]);
                                                });
                                            });
                                            msg.once('attributes', function (attrs) {
                                                console.log(prefix + 'Attributes: ' + inspect(attrs, false, 8));
                                            });
                                            msg.once('end', function () {
                                                console.log(prefix + 'Finished');
                                            });
                                        });
                                        f.once('error', function (err) {
                                            console.log('Fetch error: ' + err);
                                        });
                                        f.once('end', function () {
                                            console.log('Done fetching all messages!');
                                            imap.end();
                                        });
                                    });
                                });
                                
                                imap.once('error', function (err) {
                                    console.log(err);
                                });
                                
                                imap.once('end', function () {
                                    console.log('Connection ended');
                                });
                                
                                imap.connect();
                                
                                onStop(() => {
                                    imap.end();
                                })
                                
                                
                                M 1 Reply Last reply Reply Quote 0
                                • M
                                  Masl @fastfoot last edited by

                                  @fastfoot Kannst du mir zufällig helfen, wie man einen Datenpunkt mit dieser Vorlage erstellt die man später auslesen kann? Der Mail-Listener bringt mir nur Fehler...

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

                                  Support us

                                  ioBroker
                                  Community Adapters
                                  Donate
                                  FAQ Cloud / IOT
                                  HowTo: Node.js-Update
                                  HowTo: Backup/Restore
                                  Downloads
                                  BLOG

                                  873
                                  Online

                                  31.8k
                                  Users

                                  79.9k
                                  Topics

                                  1.3m
                                  Posts

                                  5
                                  15
                                  811
                                  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