Ionic 4 IMAP

Hi,

I’m developing an email application using Ionic 4.

I want to connect the email providers that support IMAP on my application.

I managed to install the IMAP Client plugin https://www.npmjs.com/package/emailjs-imap-client and solved all of its problems using these 2 plugins:

ionic cordova plugin add cordova-plugin-chrome-apps-sockets-tcp

ionic cordova plugin add cordova-plugin-chrome-apps-runtime

The application is able to download emails, but the plugin is very unreliable which makes my whole feature unreliable.

The plugin downloads several email messages before stopping and returning the following error:

Error: Socket timed out!
at home-home-module-es2015.js:3607
at ZoneDelegate.invokeTask (polyfills-es2015.js:3741)
at Zone.runTask (polyfills-es2015.js:3518)
at invokeTask (polyfills-es2015.js:3815)
at ZoneTask.invoke (polyfills-es2015.js:3804)
at timer (polyfills-es2015.js:6000)

Can anyone help me? Has anyone tried something like this on an Ionic project?

I have also tried to use a different IMAP plugin https://www.npmjs.com/package/imap, but I wasn’t able to make it work on an Ionic 4 project.

Sorry, I never posed a code example of what I’m trying to produce.

First, I start a blank Ionic project with the Angular framework .

Then, I install the following plugins:

npm i emailjs-imap-client

ionic cordova plugin add cordova-plugin-chrome-apps-sockets-tcp

ionic cordova plugin add cordova-plugin-chrome-apps-runtime

Then, I update my package.json file with the following to solve the errors

"browser": {
"net": false,
"tls": false
},

Then I do the following:

import ImapClient from 'emailjs-imap-client';


const client: any = new ImapClient('imap.gmx.com', 993, {
            auth: {
                user: username,
                pass: password
            }
        });

        client.connect().then(() => {
            console.log('server connected');

            client.search('INBOX', {since: new Date(2019, 1, 10, 0, 0, 0)}).then(async (messages) => {
                console.log(messages);

                let counter = 0;
                while (counter < messages.length) {
                    console.log(messages[counter]);
                    const message = await client.listMessages('INBOX', messages[counter], ['uid', 'flags', 'envelope', 'body[]']);

                    console.log('message');
                    console.log(message);

                    counter++;
                }
            }).catch((err) => {
                console.log('failed');
                console.log(err);
            });


        }).catch(err => console.log(err));

The reason why I’m downloading the messages with their full content one by one is because, I want to first process the data content of the downloaded message and then download a new one.

The application downloads a certain number of messages and then stops and returns the above error “Socket timeout”.

I have tested the “IMAP Client” plugin on a NodeJS project and its working fine, I failed to break it by downloading a larger number of messages.