Docly Developers
Function API only Updated 22 Oct 2026

imap.connect(config)

Creates a new imap session and connects to server.

Parameters

configobject | stringrequired

Uses the same setup as POP3, plus the property "method" with one of the values Login, CRAMMD5, SaslOAuth or OAuth2 (optional). For OAuth, password is the access token.

useSsl: true connects with TLS from the start (port 993). false uses STARTTLS when the server offers it (port 143).

Or pass the path to a document under #/ that holds these values, such as "#/My Imap": a path reads the values of that document, the same as docly.getJson("#/My Imap"). Throws "Mail configuration document not found" if there is no such document.

Returns

An object with the imap session. Close it with imap.disconnect when you are done.

Example

Normal JavaScript, running in the browser or on the Docly™ server.
// Configure connection (same setup as POP3 + a method property)
let config = {
    "hostname" : "serverhost",
    "port" : 993,
    "useSsl" : true,   // true = TLS from the start (port 993). false = STARTTLS when available (port 143)
    "username" : "login",
    "password" : "pass",
    "method" : "Login"
};

let i = imap.connect(config);
let count = imap.getCount(i);
if (count > 0) {
    let msg = imap.getMessage(i, 0);
    imap.delete(i, msg);
    return msg;
}
return "No emails in inbox";