Search code examples
angularnpmimap

Angular 4 imap client building, error with Semver


I'm trying to implement an Imap Client in Angular 4. I need it in my app.

I've found a node module which implement Imap with npm : Repo

But i've got a problem. I add the following line in angular-cli.json

"scripts": [
    ...,
    "../node_modules/imap/lib/Connection.js"
  ],

and then import it in my MailboxModule

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MailboxComponent } from './mailbox.component';
import * as Imap from 'imap' ;

@NgModule({
  imports: [
    CommonModule,
    Imap
  ],
  providers : [  ],
  declarations: [MailboxComponent]
})
export class MailboxModule { }

The code compiles well but I end up with the following error in my WebBrowser Console :

Uncaught TypeError: Invalid Version: 
  at new SemVer (semver.js:293)
  at compare (semver.js:566)
  at Function.gte (semver.js:615)
  at Object.<anonymous> (utf7.js:4)
  at Object.../../../../utf7/utf7.js (utf7.js:119)
  at __webpack_require__ (bootstrap 55f9ac3…:54)
  at Object.<anonymous> (Connection.js:7)
  at Object.../../../../imap/lib/Connection.js (Connection.js:2128)
  at __webpack_require__ (bootstrap 55f9ac3…:54)
  at Object.../../../../../src/app/mailbox/mailbox.module.ts (mailbox.component.ts:11)

Here is the MailboxComponent (classic)

import { Component, OnInit } from '@angular/core';


@Component({
  selector: 'app-mailbox',
  templateUrl: './mailbox.component.html',
  styleUrls: ['./mailbox.component.css']
})
export class MailboxComponent implements OnInit {
  constructor() { }

  ngOnInit() {

  }
}

Solution

  • It appears that, because webBrowsers cannot open TCP sockets, we cannot get an email client directly IN my webapp. I need a backend which connect to the mail server with IMAP or other mail protocoles, and then returns mail through API that I'll call in my webapp.