Self hosted application to access IMAP accounts over REST.
- IMAP API allows simple access to IMAP accounts via REST based API. No need to know IMAP or MIME internals, you get a "normal" API with paged message listings. All text (that is subjects, email addresses, text and html content etc) is utf-8. Attachments are automatically decoded to binary representation.
- Partial text download. You can obviously download the entire rfc822 formatted raw message but it might be easier to use provided paging and message details. This also allows to specifiy maximum size for downloaded text content. Sometimes automated cron scripts etc send emails with 10+MB text so to avoid downloading that stuff IMAP API allows to set max cap size for text.
- Whenever something happens on tracked accounts IMAP API posts notification over a webhook. This includes new messages, deleted messages and message flag changes.
- No data ever leaves your system
- Easy email sending. If you specify the message you are responding to or forwarding then IMAP API sets all required headers, updates references message's flags in IMAP and also uploads message to the Sent Mail folder after sending.
- IMAP API is a rather thin wrapper over IMAP. This means it does not have a storage of its own. It also means that if the IMAP connection is currently not open, you get a gateway error as a result of your API request.
IMAP API requires Redis to be available. For any special configuration edit config/default.toml configuration file.
$ npm install
$ npm start
Once application is started open http://127.0.0.1:3000/ for instructions and API documentation.
Open the Settings tab and set an URL for webhooks. Whenever something happens with any of the tracked email accounts you get a notification to this URL.
For example if flags are updated for a message you'd get a notification that looks like this:
{
"account": "example",
"path": "[Google Mail]/All Mail",
"event": "messageUpdated",
"data": {
"id": "AAAAAQAAAeE",
"uid": 350861,
"changes": {
"flags": {
"added": ["\\Seen"]
}
}
}
}
You need IMAP and SMTP settings and also provide some kind of an identification string value for this account. You can use the same IDs as your main system or generate some unique ones. This value is later needed to identify this account and to perform operations on it.
$ curl -XPOST "localhost:3000/v1/account" -H "content-type: application/json" -d '{
"account": "example",
"name": "My Example Account",
"imap": {
"host": "imap.gmail.com",
"port": 993,
"secure": true,
"auth": {
"user": "[email protected]",
"pass": "verysecret"
}
},
"smtp": {
"host": "smtp.gmail.com",
"port": 465,
"secure": true,
"auth": {
"user": "[email protected]",
"pass": "verysecret"
}
}
}'
Now whenever something happens you get a notification. If this is not enought then you can perform normal operations with the IMAP account as well.
IMAP API returns paged results, newer messages first. So to get the first page or in other words the newest messages in a mailbox folder you can do it like this (notice the "example" id string that we set earlier in the request URL):
$ curl -XGET "localhost:3000/v1/account/example/messages?path=INBOX"
In the response you should see a listing of messages.
{
"page": 0,
"pages": 10,
"messages": [
{
"id": "AAAAAQAAAeE",
"uid": 481,
"date": "2019-10-07T06:05:23.000Z",
"size": 4334,
"subject": "Test message",
"from": {
"name": "Peter Põder",
"address": "[email protected]"
},
"to": [
{
"name": "",
"address": "[email protected]"
}
],
"messageId": "<[email protected]>",
"text": {
"id": "AAAAAQAAAeGTkaExkaEykA",
"encodedSize": {
"plain": 17,
"html": 2135
}
}
}
]
}
Entire API descripion is available in the application as a swagger page.
Licensed for evaluation use only