Skip to main content

Imap

This plugin will enable an Ionic application to use the IMAP (Internet Message Access Protocol) features. This plugin is in Beta version and it offers support only for Android. The plugin uses Java Mail API. Planned improvements and support for iOS.

https://github.com/aleksandar888/cordova-plugin-imap.git

Stuck on a Cordova issue?

Don't waste precious time on plugin issues.

If you're building a serious project, you can't afford to spend hours troubleshooting. Ionic’s experts offer premium advisory services for both community plugins and premier plugins.

Installation#

$ npm install cordova-plugin-imap
$ npm install @ionic-native/imap
$ ionic cap sync

Supported Platforms#

  • Android

Usage#

React#

Learn more about using Ionic Native components in React

Angular#

import { Imap } from '@ionic-native/imap/ngx';
constructor(private imap: Imap) { }
...
this.imap.connect({
host: 'imap.gmail.com',
user: 'my_email@gmail.com',
password: 'my-pass'
})
.then((res: Connection) => console.log(res))
.catch((error) => console.error(error));
this.imap.disconnect()
.then((res: boolean) => console.log(res))
.catch((error: any) => console.error(error));
this.imap.isConnected()
.then((res: boolean) => console.log(res))
.catch((error: any) => console.error(error));
Note: Connected to an IMAP service is REQUIRED to be able to get data from the below functions.
this.imap.listMailFolders()
.then((res: boolean) => console.log(res))
.catch((error: any) => console.error(error));
this.imap.getMessageCountByFolderName('INBOX')
.then((res: number) => {
// Returns the count of the messages in the folder as a result
console.log(res)
})
.catch((error: any) => {
console.error(error)
});
this.imap.searchMessagesByDatePeriod('INBOX', 1601503200000, Comparison.GE)
.then((res: number[]) => {
// Returns array with messages' consecutive numbers
// ex. [1207, 1208, 1209]
console.log(res)
})
.catch((error: any) => {
console.error(error)
});
this.imap.listMessagesHeadersByConsecutiveNumber('INBOX', 1200, 1280)
.then((res: Message[]) => {
// Returns array with messages' headers data
console.log(res)
})
.catch((error: any) => {
console.error(error)
});
this.imap.listMessagesHeadersByDate('INBOX', 1601503200000, Comparison.GE)
.then((res: Message[]) => {
// Returns array with messages' headers data
console.log(res)
})
.catch((error: any) => {
console.error(error)
});
this.imap.getFullMessageData('INBOX', 1205)
.then((res: Message) => {
// Returns "Message" object with the full message data including attachments.
console.log(res)
})
.catch((error: any) => {
console.error(error)
});
this.imap.copyToFolder('INBOX', 'Spam', [1204, 1205, 1206, 1207])
.then((res: boolean) => {
// Returns "true" if the process is successful, else returns "false".
console.log(res)
})
.catch((error: any) => {
console.error(error)
});
* Sets a flag on a message
* "setFlag()" can be used for deleting messages setting the Delete flag to "FlagEnum.DELETED"
this.imap.setFlag('INBOX', [1206, 1205, 1204], FlagEnum.SEEN, true)
.then((res: ModificationResult) => {
// res.status - return true or false based on the deletion success
//res.modifiedMessages - for ex.[1206, 1205, 1204];
})
.catch((error: any) => {
console.error(error)
});