Skip to the documentation
TypeScript

nextmail.imports

Every method in this namespace: its signature, its parameters, what it returns and an example.

Methods

Bring an old mailbox across, straight from its mail server or from a Google Takeout, .mbox, .eml, .zip or .tgz export, with progress and a list of what did not come through.

nextmail.imports.list()

List one page of mailbox imports

Scopesthreads:readPages through results
Signature
list(options?: ImportListOptions): Promise<Page<ImportResource>>

Returns one page of the imports in the workspace, newest first. Nothing is dropped from the history, so following nextCursor while hasMore is true reaches the very first import, and listAll and iterate do that walk for you. Each carries its status, the bytes read so far out of the total, and running counts of messages seen, imported, skipped as duplicates, left out by your options and not imported.

A key limited to particular addresses sees only imports into those addresses.

Parameters

options.addressIdstring

Only imports into this address.

options.limitnumber

Rows per page, a whole number from 1 to 100. The server defaults to 25.

options.cursorstring

The nextCursor from the previous page, an import id. One that names no import this key can see is a 400 invalid_cursor.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client API key for this call only.

Returns

Page<ImportResource> with items, hasMore and nextCursor.

Example

const page = await nextmail.imports.list({ limit: 50 }) for (const item of page.items) {    console.log(item.address, item.status, item.counts.imported)}

Notes

  • A GET is retried automatically on network failure and on 408, 500, 502, 503 and 504 responses, up to the client maxRetries, and on a 429 only when it carries a Retry-After of a minute or less.

Also available in

API
GET /imports
Python
imports.list()
Ruby
imports.list
PHP
imports->list
Go
Imports.List
Java
imports().list
C#
Imports.ListAsync
CLI
openemail imports list

nextmail.imports.listAll()

Collect every mailbox import into one array

Scopesthreads:readPages through results
Signature
listAll(options?: ImportListOptions): Promise<Array<ImportResource>>

Follows nextCursor from page to page and resolves with every import in the workspace, newest first, narrowed to one address when addressId is given. A key limited to particular addresses sees only imports into those addresses.

Parameters

options.addressIdstring

Only imports into this address.

options.limitnumber

Page size per request, from 1 to 100, defaulting to 25 on the server.

options.cursorstring

An import id to start after, skipping everything newer.

options.signalAbortSignal

Cancels the request in flight and rejects the whole walk.

options.apiKeystring

Overrides the client API key for every page of this walk.

Returns

Array<ImportResource> holding every import across all pages.

Example

const imports = await nextmail.imports.listAll() const failed = imports.filter((item) => item.status === 'failed') console.log(`${failed.length} of ${imports.length} imports failed`)

Notes

  • A failure on any page rejects the whole call.

Also available in

API
GET /imports
Python
imports.list_all()
Ruby
imports.list_all
PHP
imports->listAll
Go
Imports.ListAll
Java
imports().listAll
C#
Imports.ListAllAsync

nextmail.imports.iterate()

Stream mailbox imports one at a time

Scopesthreads:readPages through results
Signature
iterate(options?: ImportListOptions): AsyncGenerator<ImportResource, void, undefined>

Returns an async generator that yields imports individually, newest first, and requests the next page only once the current one is drained. Breaking out of the loop stops the requests.

Parameters

options.addressIdstring

Only imports into this address.

options.limitnumber

Page size per request, from 1 to 100, defaulting to 25 on the server.

options.cursorstring

An import id to start after, skipping everything newer.

options.signalAbortSignal

Cancels the request in flight and rejects the whole walk.

options.apiKeystring

Overrides the client API key for every page of this walk.

Returns

AsyncGenerator<ImportResource, void, undefined> yielding one import per step.

Example

for await (const item of nextmail.imports.iterate({ addressId: 'addr_2b7e' })) {    if (item.status === 'running') {        console.log(item.id, item.counts.imported)        break    }}

Notes

  • The generator is lazy, so an abandoned loop costs only the pages you consumed.

Also available in

API
GET /imports
Python
imports.iterate()
Ruby
imports.iterate
PHP
imports->iterate
Go
Imports.Iterate
Java
imports().iterate
C#
Imports.IterateAsync

nextmail.imports.get()

Read one mailbox import

Scopesthreads:read
Signature
get(id: string, options?: RequestScope): Promise<ImportResource>

Resolves one import with its status, byte progress and counts. Poll it while status is queued or running; it settles on completed, failed or cancelled.

An import from a live mailbox has source imap or microsoft and carries remote, with the folders done out of the total and why it waits, and children, the contacts and calendar imports that came with it. Such an import can also wait: parked carries on by itself at remote.resumeAt, and needs-password stays until resume sends a new password. An import from files has source: file, remote: null and no children.

An id from another workspace answers exactly like one that never existed, with 404.

Parameters

idstringRequired

Import id, imp_ followed by 24 hex characters.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client API key for this call only.

Returns

ImportResource.

Example

const item = await nextmail.imports.get('imp_3f9c2a7b1e4d8f60a5c7b92d') console.log(item.status, item.processedBytes, '/', item.totalBytes)

Notes

  • lastError is set only when status is failed.

Also available in

API
GET /imports/{id}
Python
imports.get()
Ruby
imports.get
PHP
imports->get
Go
Imports.Get
Java
imports().get
C#
Imports.GetAsync
CLI
openemail imports get

nextmail.imports.create()

Create a mailbox import and get its upload plan

Scopesthreads:write
Signature
create(body: ImportCreate, options?: RequestScope): Promise<ImportResource>

Creates an import into one address of the workspace and returns it with status: uploading. Each file is uploaded in parts of chunkBytes, files[i].chunks of them, through uploadChunk, and start then queues the import.

The import reads Google Takeout archives, .mbox files from Apple Mail, Thunderbird and most desktop apps, .eml files, and .zip or .tgz archives holding any of those, up to 100 GB a file and 50 files an import. Threads, dates and labels come across. Imported mail is quiet: it runs no rules, forwards, notifications, summaries or webhooks.

importFiles does create, upload and start in one call.

Parameters

body.addressIdstringRequired

The address the mail belongs to. It must be an address this workspace owns and this key may act for.

body.filesArray<ImportFileDescriptor>Required

Each file as { name, bytes }, 1 to 50 of them, each at most 100 GB.

body.options.keepInboxboolean

Default true: mail that was in the old inbox lands in Inbox with its unread state. False files everything under Archive.

body.options.includeSpamboolean

Default false.

body.options.includeTrashboolean

Default false.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client API key for this call only.

Returns

ImportResource with status: uploading, chunkBytes and each file's chunks.

Example

const item = await nextmail.imports.create({    addressId: 'addr_2b7e',    files: [{ name: 'takeout-001.zip', bytes: 2147483648 }]}) console.log(item.chunkBytes, item.files[0].chunks)

Notes

  • An address with an import already queued or running is 409 already_running.

  • Not retried automatically.

Also available in

API
POST /imports
Python
imports.create()
Ruby
imports.create
PHP
imports->create
Go
Imports.Create
Java
imports().create
C#
Imports.CreateAsync
CLI
openemail imports create

nextmail.imports.uploadState()

See which parts of the upload have arrived

Scopesthreads:write
Signature
uploadState(id: string, options?: RequestScope): Promise<ImportUploadResource>

For each file, the indexes of the parts already stored, so an interrupted upload sends only what is missing. Empty once the import has left the uploading state.

Parameters

idstringRequired

Import id, imp_ followed by 24 hex characters.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client API key for this call only.

Returns

ImportUploadResource with received, one sorted array of part indexes per file.

Example

const state = await nextmail.imports.uploadState('imp_3f9c2a7b1e4d8f60a5c7b92d') console.log(state.received[0].length)

Also available in

API
GET /imports/{id}/upload
Python
imports.upload_state()
Ruby
imports.upload_state
PHP
imports->uploadState
Go
Imports.UploadState
Java
imports().uploadState
C#
Imports.UploadStateAsync
CLI
openemail imports upload-state

nextmail.imports.uploadChunk()

Upload one part of an import file

Scopesthreads:write
Signature
uploadChunk(id: string, file: number, chunk: number, data: RawBody, options?: RequestScope): Promise<ImportChunkResource>

Stores one part of file file: the bytes from chunk * chunkBytes up to the next part. Every part is exactly chunkBytes long except the last, and a part of the wrong length is 400 bad_chunk. Sending a part again replaces it, so a failed part can simply be retried.

Parameters

idstringRequired

Import id, imp_ followed by 24 hex characters.

filenumberRequired

The file index, in the order given to create.

chunknumberRequired

The part index, from 0.

dataRawBodyRequired

The part as a Blob, Uint8Array or ArrayBuffer.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client API key for this call only.

Returns

ImportChunkResource echoing file, chunk and the bytes stored.

Example

await nextmail.imports.uploadChunk(item.id, 0, 0, bytes.subarray(0, item.chunkBytes))

Notes

  • Retried automatically on network failure and on 408, 500, 502, 503 and 504 responses, and on a 429 only when it carries a Retry-After of a minute or less, since a repeated part replaces itself.

Also available in

API
PUT /imports/{id}/files/{file}/chunks/{chunk}
Python
imports.upload_chunk()
Ruby
imports.upload_chunk
PHP
imports->uploadChunk
Go
Imports.UploadChunk
Java
imports().uploadChunk
C#
Imports.UploadChunkAsync
CLI
openemail imports upload-chunk

nextmail.imports.start()

Queue an import once its files are uploaded

Scopesthreads:write
Signature
start(id: string, options?: RequestScope): Promise<ImportResource>

Checks that every part of every file has arrived, recognises each file's format and queues the import. A file still missing parts is 412 missing_chunks, and a file that is not an archive or a mailbox is 400 unsupported_file. Calling it on an import that has already left uploading returns it unchanged.

Parameters

idstringRequired

Import id, imp_ followed by 24 hex characters.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client API key for this call only.

Returns

ImportResource with status: queued.

Example

const queued = await nextmail.imports.start(item.id) console.log(queued.status)

Also available in

API
POST /imports/{id}/start
Python
imports.start()
Ruby
imports.start
PHP
imports->start
Go
Imports.Start
Java
imports().start
C#
Imports.StartAsync
CLI
openemail imports start

nextmail.imports.cancel()

Cancel a mailbox import

Scopesthreads:write
Signature
cancel(id: string, options?: RequestScope): Promise<ImportResource>

Stops an import at its next checkpoint. Mail already imported stays in the mailbox. A finished import is 409 not_cancellable.

Parameters

idstringRequired

Import id, imp_ followed by 24 hex characters.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client API key for this call only.

Returns

ImportResource with status: cancelled.

Example

await nextmail.imports.cancel('imp_3f9c2a7b1e4d8f60a5c7b92d')

Also available in

API
POST /imports/{id}/cancel
Python
imports.cancel()
Ruby
imports.cancel
PHP
imports->cancel
Go
Imports.Cancel
Java
imports().cancel
C#
Imports.CancelAsync
CLI
openemail imports cancel

nextmail.imports.listFailures()

List what an import could not bring across

Scopesthreads:read
Signature
listFailures(id: string, options?: ImportFailuresOptions): Promise<ImportFailurePage>

Each message or archive entry that did not come across, with the reason: too-large (over 50 MB), unparseable, no-date, storage-error, unreadable-entry, encrypted-entry or archive-limit. Page with after, passing the nextCursor of the previous page.

Parameters

idstringRequired

Import id, imp_ followed by 24 hex characters.

options.afternumber

The nextCursor of the previous page.

options.limitnumber

At most 100, the default.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client API key for this call only.

Returns

ImportFailurePage with data and nextCursor.

Example

const page = await nextmail.imports.listFailures(item.id) for (const failure of page.data) console.log(failure.reason, failure.subject)

Also available in

API
GET /imports/{id}/failures
Python
imports.list_failures()
Ruby
imports.list_failures
PHP
imports->listFailures
Go
Imports.ListFailures
Java
imports().listFailures
C#
Imports.ListFailuresAsync
CLI
openemail imports list-failures

nextmail.imports.deleteUpload()

Delete the files uploaded for an import

Scopesthreads:write
Signature
deleteUpload(id: string, options?: RequestScope): Promise<ImportResource>

Removes the uploaded archive. Mail already imported stays in the mailbox. An import still uploading is cancelled at the same time, and one that is queued or running is 409 still_running.

Parameters

idstringRequired

Import id, imp_ followed by 24 hex characters.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client API key for this call only.

Returns

ImportResource with uploadDeleted: true.

Example

await nextmail.imports.deleteUpload('imp_3f9c2a7b1e4d8f60a5c7b92d')

Also available in

API
DELETE /imports/{id}/upload
Python
imports.delete_upload()
Ruby
imports.delete_upload
PHP
imports->deleteUpload
Go
Imports.DeleteUpload
Java
imports().deleteUpload
C#
Imports.DeleteUploadAsync
CLI
openemail imports delete-upload

nextmail.imports.importFiles()

Create, upload and start an import in one call

Scopesthreads:write
Signature
importFiles(input: ImportFilesInput, options?: RequestScope): Promise<ImportResource>

Creates the import, uploads every file part by part and starts it, reporting progress through onProgress. Pass each file as a Blob, Uint8Array or ArrayBuffer; parts are sliced from it, so a Blob backed by a file on disk is never read into memory at once.

It resolves once the import is queued. Poll get to follow it.

Parameters

input.addressIdstringRequired

The address the mail belongs to.

input.filesArray<ImportSource>Required

Each file as { name, data }.

input.optionsImportOptions

keepInbox, includeSpam and includeTrash, as for create.

input.onProgressImportProgress

Called after each part with the bytes uploaded and the total.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client API key for this call only.

Returns

ImportResource with status: queued.

Example

import { openAsBlob } from 'node:fs' const takeout = await openAsBlob('takeout-001.zip') const item = await nextmail.imports.importFiles({    addressId: 'addr_2b7e',    files: [{ name: 'takeout-001.zip', data: takeout }],    onProgress: (done, total) => console.log(Math.round((done / total) * 100) + '%')})

Notes

  • If a part fails after its retries, the import is left in uploading; uploadState then tells you which parts to send before calling start.

Also available in

API
POST /imports
Python
imports.import_files()
Ruby
imports.import_files
PHP
imports->importFiles
Go
Imports.ImportFiles
Java
imports().importFiles
C#
Imports.ImportFilesAsync
CLI
openemail imports import-files

nextmail.imports.discoverMailbox()

Find the mail server for an address

Scopesthreads:write
Signature
discoverMailbox(email: string, options?: RequestScope): Promise<MailboxSettingsResource>

Looks up where the mailbox behind an address lives, so an import can connect to it. It tries the providers Nextmail knows, then who receives mail for the domain, then Mozilla's public list of mail settings, then the domain's own _imaps._tcp record. Nothing is stored and no sign-in is attempted.

server is null when nothing was found: ask for the host and port and pass them to checkMailbox. signIn says what the mailbox takes. app-password and password are what checkMailbox and connectMailbox send. An Outlook.com or Microsoft 365 mailbox answers microsoft, which only the Microsoft sign-in on the Migrations page of the app can open.

Parameters

emailstringRequired

The address of the old mailbox.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client API key for this call only.

Returns

MailboxSettingsResource with provider, signIn, server, source, username and whether contacts and calendars can come across too.

Example

const settings = await nextmail.imports.discoverMailbox('[email protected]') if (settings.signIn === 'microsoft') console.log('Connect this mailbox from the Migrations page of the app')else console.log(settings.provider, settings.signIn, settings.server?.host)

Notes

  • Something that is not an email address is a 400 mailbox_address_invalid.

  • Too many lookups in an hour is a 429 mailbox_checks_limited.

  • A GET is retried automatically on network failure and on 408, 500, 502, 503 and 504 responses, up to the client maxRetries, and on a 429 only when it carries a Retry-After of a minute or less.

Also available in

API
GET /imports/mailbox-settings
Python
imports.discover_mailbox()
Ruby
imports.discover_mailbox
PHP
imports->discoverMailbox
Go
Imports.DiscoverMailbox
Java
imports().discoverMailbox
C#
Imports.DiscoverMailboxAsync
CLI
openemail imports discover-mailbox

nextmail.imports.checkMailbox()

Check a mailbox before importing it

Scopesthreads:write
Signature
checkMailbox(body: MailboxCheckInput, options?: RequestScope): Promise<MailboxCheckResource>

Signs in to the old mailbox over IMAP, lists its folders and counts the messages, then signs out. Nothing is stored, the password is not kept and the old mailbox is not changed. Use it to show what an import would bring before starting one.

Leave host out to have the server looked up from the address, as discoverMailbox does. Only port 993 with TLS, or port 143 with STARTTLS, is accepted. Each person may make 10 sign-in attempts an hour across checkMailbox, connectMailbox and resume, and every refused sign-in reads the same, whatever the reason.

Parameters

body.emailstringRequired

The address of the old mailbox.

body.passwordstringRequired

The password of the old mailbox, or an app password where discoverMailbox answers signIn: app-password.

body.hoststring

The IMAP host, such as imap.example.com. It has to be a public host. Left out, the server is looked up from the address.

body.portnumber

993 or 143, read only with host. Left out, it follows security: 993 for tls and 143 for starttls.

body.securityMailboxSecurity

tls or starttls, read only with host. Left out, it follows port, and is tls when both are left out.

body.usernamestring

The name to sign in with. Left out, it is the username that discoverMailbox answers, usually the address.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client API key for this call only.

Returns

MailboxCheckResource with the server and username that worked, up to 200 folders with their role, messages and whether an import with the default options reads them, and the total messages an import would read.

Example

const check = await nextmail.imports.checkMailbox({    email: '[email protected]',    password: process.env.OLD_MAILBOX_PASSWORD!}) console.log(`${check.messages} messages in ${check.folders.filter((folder) => folder.included).length} folders`)

Notes

Also available in

API
POST /imports/mailbox/check
Python
imports.check_mailbox()
Ruby
imports.check_mailbox
PHP
imports->checkMailbox
Go
Imports.CheckMailbox
Java
imports().checkMailbox
C#
Imports.CheckMailboxAsync
CLI
openemail imports check-mailbox

nextmail.imports.connectMailbox()

Import a live mailbox

Scopesthreads:write
Signature
connectMailbox(body: MailboxConnectInput, options?: RequestScope): Promise<ImportResource>

Starts copying an old mailbox into one address, straight from its mail server. It signs in once to check the password, keeps the password sealed until the import finishes and for 30 days at most, and queues the import. Poll get for progress.

The old mailbox is only ever read. Folders become labels, read and starred state come across, and a message the address already holds is skipped, so running an import twice adds nothing. A Gmail mailbox is read from All Mail, with its labels. An import waits by itself when the old provider slows it down, such as Gmail's daily download limit, and carries on from the same folder afterwards: status is parked and remote.resumeAt says when. If the password stops working, status is needs-password until resume sends a new one.

contacts and calendars bring those across too where the provider offers them, which needs contacts:write and calendar:write as well. They arrive as contacts and calendar imports of their own, listed in children. rerunOf names a finished import of the same mailbox, at most 30 days old, so only mail that arrived since is fetched. One import may run into an address at a time.

Parameters

body.addressIdstringRequired

The address the mail belongs to. It must be an address this workspace owns and this key may act for.

body.emailstringRequired

The address of the old mailbox.

body.passwordstringRequired

The password of the old mailbox, or an app password where discoverMailbox answers signIn: app-password.

body.hoststring

The IMAP host, such as imap.example.com. It has to be a public host. Left out, the server is looked up from the address.

body.portnumber

993 or 143, read only with host. Left out, it follows security: 993 for tls and 143 for starttls.

body.securityMailboxSecurity

tls or starttls, read only with host. Left out, it follows port, and is tls when both are left out.

body.usernamestring

The name to sign in with. Left out, it is the username that discoverMailbox answers, usually the address.

body.options.keepInboxboolean

Default true: mail that was in the old inbox lands in Inbox with its unread state. False files everything under Archive.

body.options.includeSpamboolean

Default false.

body.options.includeTrashboolean

Default false.

body.contactsboolean

True brings the address book across too, where the provider offers it. Needs contacts:write.

body.calendarsboolean

True brings the calendars across too, where the provider offers them. Needs calendar:write.

body.rerunOfstring

The id of a finished import of the same mailbox, at most 30 days old. Only mail that arrived since is fetched.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client API key for this call only.

Returns

ImportResource with status: queued, source: imap, the remote mailbox it reads and the children it started.

Example

const item = await nextmail.imports.connectMailbox({    addressId: 'addr_2b7e',    email: '[email protected]',    password: process.env.OLD_MAILBOX_PASSWORD!,    contacts: true,    calendars: true}) console.log(item.status, item.remote?.host, item.children.length)

Notes

Also available in

API
POST /imports/mailbox
Python
imports.connect_mailbox()
Ruby
imports.connect_mailbox
PHP
imports->connectMailbox
Go
Imports.ConnectMailbox
Java
imports().connectMailbox
C#
Imports.ConnectMailboxAsync
CLI
openemail imports connect-mailbox

nextmail.imports.resume()

Resume a waiting mailbox import

Scopesthreads:write
Signature
resume(id: string, body?: ImportResumeInput, options?: RequestScope): Promise<ImportResource>

Carries on an import from a live mailbox that is waiting. One with status: parked is queued again at once, without a body. One with status: needs-password needs the new password, which is checked against the old mailbox before the import is queued. It picks up at the folder and message it stopped at.

An import that came from a Microsoft sign-in is resumed by signing in again on the Migrations page of the app.

Parameters

idstringRequired

Import id, imp_ followed by 24 hex characters.

body.passwordstring

The new password of the old mailbox. Required when status is needs-password.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client API key for this call only.

Returns

ImportResource with status: queued.

Example

const parked = await nextmail.imports.resume('imp_3f9c2a7b1e4d8f60a5c7b92d') console.log(parked.status) const signedIn = await nextmail.imports.resume('imp_9d2c7b5a06f8d4e1b7a2c9f3', {    password: process.env.OLD_MAILBOX_PASSWORD!}) console.log(signedIn.status)

Notes

  • An import that is not waiting, or that reads uploaded files, is 409 not_resumable.

  • Leaving password out for an import that needs one is 400 password_required, and a password the mail server does not accept is 400 mailbox_login_failed.

  • A new password counts towards the 10 sign-in attempts an hour that checkMailbox and connectMailbox share.

  • A parked import carries on by itself at remote.resumeAt, so calling this only tries sooner.

  • Not retried automatically.

Also available in

API
POST /imports/{id}/resume
Python
imports.resume()
Ruby
imports.resume
PHP
imports->resume
Go
Imports.Resume
Java
imports().resume
C#
Imports.ResumeAsync
CLI
openemail imports resume