Skip to the documentation
Python

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.

imports.list()

List one page of mailbox imports

Scopesthreads:readPages through results
Signature
def list(    *,    limit: int | None = None,    cursor: str | None = None,    address_id: str | None = None,    api_key: str | None = None,    timeout: float | None = None,) -> 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 list_all 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

limitint

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

cursorstr

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

address_idstr

Only imports into the address with this id.

api_keystr

Overrides the client's API key for this call only.

timeoutfloat

Seconds this call may take, the response included, before it raises NextmailNetworkError with is_timeout. It overrides the client's timeout for this call, and 0 turns the limit off.

Returns

Page[ImportResource], a dict with items, hasMore and nextCursor.

Example

from nextmail import nextmail page = nextmail.imports.list(limit=50) for item in page['items']:    print(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's max_retries, and on a 429 only when it carries a Retry-After of a minute or less.

Also available in

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

imports.list_all()

Collect every mailbox import into one list

Scopesthreads:readPages through results
Signature
def list_all(    *,    limit: int | None = None,    cursor: str | None = None,    address_id: str | None = None,    api_key: str | None = None,    timeout: float | None = None,) -> builtins.list[ImportResource]

Follows nextCursor from page to page and returns every import in the workspace as one list, newest first, narrowed to one address when address_id= is given. A key limited to particular addresses sees only imports into those addresses.

Parameters

limitint

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

cursorstr

An import id to start after, skipping everything newer.

address_idstr

Only imports into the address with this id.

api_keystr

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

timeoutfloat

Seconds this call may take, the response included, before it raises NextmailNetworkError with is_timeout. It overrides the client's timeout for this call, and 0 turns the limit off.

Returns

list[ImportResource] holding every import across all pages.

Example

from nextmail import nextmail imports = nextmail.imports.list_all()failed = [item for item in imports if item['status'] == 'failed'] print(f'{len(failed)} of {len(imports)} imports failed')

Notes

  • A failure on any page makes the whole call raise, and the imports already fetched are discarded.

Also available in

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

imports.iterate()

Stream mailbox imports one at a time

Scopesthreads:readPages through results
Signature
def iterate(    *,    limit: int | None = None,    cursor: str | None = None,    address_id: str | None = None,    api_key: str | None = None,    timeout: float | None = None,) -> Iterator[ImportResource]

Returns a generator that yields imports one at a time, newest first, and requests the next page only once the current one is used up. Nothing is fetched until you start iterating, and breaking out of the loop stops the requests.

Parameters

limitint

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

cursorstr

An import id to start after, skipping everything newer.

address_idstr

Only imports into the address with this id.

api_keystr

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

timeoutfloat

Seconds this call may take, the response included, before it raises NextmailNetworkError with is_timeout. It overrides the client's timeout for this call, and 0 turns the limit off.

Returns

Iterator[ImportResource], a generator yielding one import per step.

Example

from nextmail import nextmail for item in nextmail.imports.iterate(address_id='7c9d2e41-0b8f-4a63-9e25-1f4d6a8b3c70'):    if item['status'] == 'running':        print(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
TypeScript
nextmail.imports.iterate()
Ruby
imports.iterate
PHP
imports->iterate
Go
Imports.Iterate
Java
imports().iterate
C#
Imports.IterateAsync

imports.get()

Read one mailbox import

Scopesthreads:read
Signature
def get(    id: str,    *,    api_key: str | None = None,    timeout: float | None = None,) -> ImportResource

Returns 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 set to 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 set to file, remote set to None and no children.

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

Parameters

idstrRequired

Import id, imp_ followed by 24 hex characters.

api_keystr

Overrides the client's API key for this call only.

timeoutfloat

Seconds this call may take, the response included, before it raises NextmailNetworkError with is_timeout. It overrides the client's timeout for this call, and 0 turns the limit off.

Returns

ImportResource.

Example

from nextmail import nextmail item = nextmail.imports.get('imp_3f9c2a7b1e4d8f60a5c7b92d') print(item['status'], item['processedBytes'], '/', item['totalBytes'])

Notes

  • lastError is set only when status is failed.

Also available in

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

imports.create()

Create a mailbox import and get its upload plan

Scopesthreads:write
Signature
def create(    body: ImportCreate,    *,    api_key: str | None = None,    timeout: float | None = None,) -> ImportResource

Creates an import into one address of the workspace and returns it with status set to uploading. Each file is uploaded through upload_chunk in parts of chunkBytes, as many as its entry in files gives in chunks, 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.

import_files does create, upload and start in one call.

Parameters

body['addressId']strRequired

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

body['files']list[ImportFileDescriptor]Required

Each file as a dict of its name and its size in bytes, such as {'name': 'takeout-001.zip', 'bytes': 2147483648}, 1 to 50 of them, each at most 100 GB.

body['options']['keepInbox']bool

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

body['options']['includeSpam']bool

True brings the mail in the old spam folder across too, into Spam. Defaults to False, which leaves it out.

body['options']['includeTrash']bool

True brings the mail in the old trash across too, into the Bin. Defaults to False, which leaves it out.

api_keystr

Overrides the client's API key for this call only.

timeoutfloat

Seconds this call may take, the response included, before it raises NextmailNetworkError with is_timeout. It overrides the client's timeout for this call, and 0 turns the limit off.

Returns

ImportResource with status set to uploading, chunkBytes, and each file's chunks in files.

Example

from pathlib import Path from nextmail import nextmail archive = Path('archive.zip')item = nextmail.imports.create(    {        'addressId': '7c9d2e41-0b8f-4a63-9e25-1f4d6a8b3c70',        'files': [{'name': 'takeout-001.zip', 'bytes': archive.stat().st_size}],        'options': {'keepInbox': False, 'includeTrash': True},    }) print(item['id'], item['chunkBytes'], item['files'][0]['chunks'])

Notes

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

  • Not retried automatically by the SDK.

Also available in

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

imports.upload_state()

See which parts of the upload have arrived

Scopesthreads:write
Signature
def upload_state(    id: str,    *,    api_key: str | None = None,    timeout: float | None = None,) -> 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

idstrRequired

Import id, imp_ followed by 24 hex characters.

api_keystr

Overrides the client's API key for this call only.

timeoutfloat

Seconds this call may take, the response included, before it raises NextmailNetworkError with is_timeout. It overrides the client's timeout for this call, and 0 turns the limit off.

Returns

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

Example

from nextmail import nextmail state = nextmail.imports.upload_state('imp_3f9c2a7b1e4d8f60a5c7b92d') for file, parts in enumerate(state['received']):    print(f'file {file}: {len(parts)} parts stored')

Also available in

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

imports.upload_chunk()

Upload one part of an import file

Scopesthreads:write
Signature
def upload_chunk(    id: str,    file: int,    chunk: int,    data: RawBody,    *,    api_key: str | None = None,    timeout: float | None = None,) -> 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

idstrRequired

Import id, imp_ followed by 24 hex characters.

fileintRequired

The file index, in the order given to create.

chunkintRequired

The part index, from 0.

dataRawBodyRequired

The part as bytes, bytearray or memoryview.

api_keystr

Overrides the client's API key for this call only.

timeoutfloat

Seconds this call may take, the response included, before it raises NextmailNetworkError with is_timeout. It overrides the client's timeout for this call, and 0 turns the limit off.

Returns

ImportChunkResource echoing file, chunk and the bytes stored.

Example

from pathlib import Path from nextmail import nextmail content = Path('mailbox.mbox').read_bytes()item = nextmail.imports.create(    {        'addressId': '7c9d2e41-0b8f-4a63-9e25-1f4d6a8b3c70',        'files': [{'name': 'mailbox.mbox', 'bytes': len(content)}],    })size = item['chunkBytes'] for chunk in range(item['files'][0]['chunks']):    part = content[chunk * size : (chunk + 1) * size]    stored = nextmail.imports.upload_chunk(item['id'], 0, chunk, part)    print(stored['chunk'], stored['bytes'])

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}
TypeScript
nextmail.imports.uploadChunk()
Ruby
imports.upload_chunk
PHP
imports->uploadChunk
Go
Imports.UploadChunk
Java
imports().uploadChunk
C#
Imports.UploadChunkAsync
CLI
nextmail imports upload-chunk

imports.start()

Queue an import once its files are uploaded

Scopesthreads:write
Signature
def start(    id: str,    *,    api_key: str | None = None,    timeout: float | None = None,) -> 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

idstrRequired

Import id, imp_ followed by 24 hex characters.

api_keystr

Overrides the client's API key for this call only.

timeoutfloat

Seconds this call may take, the response included, before it raises NextmailNetworkError with is_timeout. It overrides the client's timeout for this call, and 0 turns the limit off.

Returns

ImportResource with status set to queued.

Example

from nextmail import NextmailApiError, nextmail try:    queued = nextmail.imports.start('imp_3f9c2a7b1e4d8f60a5c7b92d')except NextmailApiError as error:    if error.code != 'missing_chunks':        raise    print(error.message)else:    print(queued['status'], queued['formats'])

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 starting an import that already started returns it unchanged.

Also available in

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

imports.cancel()

Cancel a mailbox import

Scopesthreads:write
Signature
def cancel(    id: str,    *,    api_key: str | None = None,    timeout: float | None = None,) -> ImportResource

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

Parameters

idstrRequired

Import id, imp_ followed by 24 hex characters.

api_keystr

Overrides the client's API key for this call only.

timeoutfloat

Seconds this call may take, the response included, before it raises NextmailNetworkError with is_timeout. It overrides the client's timeout for this call, and 0 turns the limit off.

Returns

ImportResource with status set to cancelled.

Example

from nextmail import nextmail item = nextmail.imports.cancel('imp_3f9c2a7b1e4d8f60a5c7b92d') print(item['status'], item['counts']['imported'], 'messages kept')

Also available in

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

imports.list_failures()

List what an import could not bring across

Scopesthreads:read
Signature
def list_failures(    id: str,    *,    after: int | None = None,    limit: int | None = None,    api_key: str | None = None,    timeout: float | None = None,) -> 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

idstrRequired

Import id, imp_ followed by 24 hex characters.

afterint

The nextCursor of the previous page.

limitint

At most 100, the default.

api_keystr

Overrides the client's API key for this call only.

timeoutfloat

Seconds this call may take, the response included, before it raises NextmailNetworkError with is_timeout. It overrides the client's timeout for this call, and 0 turns the limit off.

Returns

ImportFailurePage with the failures in data and nextCursor, an int while more follow and None on the last page.

Example

from nextmail import nextmail page = nextmail.imports.list_failures('imp_3f9c2a7b1e4d8f60a5c7b92d', limit=100) for failure in page['data']:    print(failure['reason'], failure['subject'], failure['detail']) if page['nextCursor'] is not None:    more = nextmail.imports.list_failures(        'imp_3f9c2a7b1e4d8f60a5c7b92d', after=page['nextCursor'], limit=100    )    print(len(more['data']), 'more on the next page')

Also available in

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

imports.delete_upload()

Delete the files uploaded for an import

Scopesthreads:write
Signature
def delete_upload(    id: str,    *,    api_key: str | None = None,    timeout: float | None = None,) -> 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

idstrRequired

Import id, imp_ followed by 24 hex characters.

api_keystr

Overrides the client's API key for this call only.

timeoutfloat

Seconds this call may take, the response included, before it raises NextmailNetworkError with is_timeout. It overrides the client's timeout for this call, and 0 turns the limit off.

Returns

ImportResource with uploadDeleted set to True.

Example

from nextmail import nextmail item = nextmail.imports.delete_upload('imp_3f9c2a7b1e4d8f60a5c7b92d') print(item['uploadDeleted'], item['status'])

Also available in

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

imports.import_files()

Create, upload and start an import in one call

Scopesthreads:write
Signature
def import_files(    input: ImportFilesInput,    *,    api_key: str | None = None,    timeout: float | None = None,) -> ImportResource

Creates the import, uploads every file part by part and starts it, calling onProgress after each part. Pass each file's content as bytes, bytearray or memoryview. Parts are sliced from it without copying the whole file, so a memoryview of an mmap over the file on disk keeps a large archive out of memory.

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

Parameters

input['addressId']strRequired

The id of the address the mail belongs to.

input['files']list[ImportSource]Required

Each file as a dict of its name and its content in data, such as {'name': 'takeout-001.zip', 'data': content}.

input['options']ImportOptions

keepInbox, includeSpam and includeTrash, as for create.

input['onProgress']ImportProgress

A function called after each part with two ints: the bytes uploaded so far and the total.

api_keystr

Overrides the client's API key for every request this call makes.

timeoutfloat

Seconds each of its requests may take, the response included, before it raises NextmailNetworkError with is_timeout. It limits the create, every part and the start one at a time, not the upload as a whole. It overrides the client's timeout, and 0 turns the limit off.

Returns

ImportResource with status set to queued.

Example

from pathlib import Path from nextmail import nextmail item = nextmail.imports.import_files(    {        'addressId': '7c9d2e41-0b8f-4a63-9e25-1f4d6a8b3c70',        'files': [{'name': 'takeout-001.zip', 'data': Path('archive.zip').read_bytes()}],        'onProgress': lambda done, total: print(f'{done} of {total} bytes uploaded'),    }) print(item['id'], item['status'])

Notes

  • If a part still fails after its retries, the call raises and the import is left in uploading. upload_state then says which parts to send before calling start.

Also available in

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

imports.discover_mailbox()

Find the mail server for an address

Scopesthreads:write
Signature
def discover_mailbox(    email: str,    *,    api_key: str | None = None,    timeout: float | None = None,) -> 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 None when nothing was found: ask for the host and port and pass them to check_mailbox. signIn says what the mailbox takes. app-password and password are what check_mailbox and connect_mailbox 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

emailstrRequired

The address of the old mailbox.

api_keystr

Overrides the client's API key for this call only.

timeoutfloat

Seconds this call may take, the response included, before it raises NextmailNetworkError with is_timeout. It overrides the client's timeout for this call, and 0 turns the limit off.

Returns

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

Example

from nextmail import nextmail settings = nextmail.imports.discover_mailbox('ada@gmail.com')server = settings['server'] if settings['signIn'] == 'microsoft':    print('Connect this mailbox from the Migrations page of the app')elif server is None:    print('Ask for the IMAP host and port, then pass them to check_mailbox')else:    print(settings['provider'], settings['signIn'], server['host'], server['port'])

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's max_retries, and on a 429 only when it carries a Retry-After of a minute or less.

Also available in

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

imports.check_mailbox()

Check a mailbox before importing it

Scopesthreads:write
Signature
def check_mailbox(    body: MailboxCheckInput,    *,    api_key: str | None = None,    timeout: float | None = None,) -> 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 discover_mailbox does. Only port 993 with TLS, or port 143 with STARTTLS, is accepted. Each person may make 10 sign-in attempts an hour across check_mailbox, connect_mailbox and resume, and every refused sign-in reads the same, whatever the reason.

Parameters

body['email']strRequired

The address of the old mailbox.

body['password']strRequired

The password of the old mailbox, or an app password where discover_mailbox answers signIn set to app-password.

body['host']str

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['port']int

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

body['security']MailboxSecurity

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

body['username']str

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

api_keystr

Overrides the client's API key for this call only.

timeoutfloat

Seconds this call may take, the response included, before it raises NextmailNetworkError with is_timeout. It overrides the client's timeout for this call, and 0 turns the limit off.

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

import os from nextmail import nextmail check = nextmail.imports.check_mailbox(    {'email': 'ada@gmail.com', 'password': os.environ.get('OLD_MAILBOX_PASSWORD', '')})included = [folder for folder in check['folders'] if folder['included']] print(check['messages'], 'messages in', len(included), 'folders')

Notes

Also available in

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

imports.connect_mailbox()

Import a live mailbox

Scopesthreads:write
Signature
def connect_mailbox(    body: MailboxConnectInput,    *,    api_key: str | None = None,    timeout: float | None = None,) -> 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['addressId']strRequired

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

body['email']strRequired

The address of the old mailbox.

body['password']strRequired

The password of the old mailbox, or an app password where discover_mailbox answers signIn set to app-password.

body['host']str

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['port']int

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

body['security']MailboxSecurity

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

body['username']str

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

body['options']['keepInbox']bool

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

body['options']['includeSpam']bool

True brings the mail in the old spam folder across too, into Spam. Defaults to False, which leaves it out.

body['options']['includeTrash']bool

True brings the mail in the old trash across too, into the Bin. Defaults to False, which leaves it out.

body['contacts']bool

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

body['calendars']bool

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

body['rerunOf']str

The id of a finished import of the same mailbox, at most 30 days old. Only mail that arrived since is fetched. Leave host out on such a run and it connects to the same server as that import.

api_keystr

Overrides the client's API key for this call only.

timeoutfloat

Seconds this call may take, the response included, before it raises NextmailNetworkError with is_timeout. It overrides the client's timeout for this call, and 0 turns the limit off.

Returns

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

Example

import os from nextmail import nextmail item = nextmail.imports.connect_mailbox(    {        'addressId': '7c9d2e41-0b8f-4a63-9e25-1f4d6a8b3c70',        'email': 'ada@gmail.com',        'password': os.environ.get('OLD_MAILBOX_PASSWORD', ''),        'contacts': True,        'calendars': True,    })remote = item['remote'] print(item['status'], remote['host'] if remote else None, len(item['children']))

Notes

Also available in

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

imports.resume()

Resume a waiting mailbox import

Scopesthreads:write
Signature
def resume(    id: str,    body: ImportResumeInput | None = None,    *,    api_key: str | None = None,    timeout: float | None = None,) -> ImportResource

Carries on an import from a live mailbox that is waiting. One with status set to parked is queued again at once, without a body. One with status set to 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

idstrRequired

Import id, imp_ followed by 24 hex characters.

body['password']str

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

api_keystr

Overrides the client's API key for this call only.

timeoutfloat

Seconds this call may take, the response included, before it raises NextmailNetworkError with is_timeout. It overrides the client's timeout for this call, and 0 turns the limit off.

Returns

ImportResource with status set to queued.

Example

import os from nextmail import nextmail parked = nextmail.imports.resume('imp_3f9c2a7b1e4d8f60a5c7b92d') print(parked['status']) signed_in = nextmail.imports.resume(    'imp_9d2c7b5a06f8d4e1b7a2c9f3', {'password': os.environ.get('OLD_MAILBOX_PASSWORD', '')}) print(signed_in['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 check_mailbox and connect_mailbox share.

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

  • Not retried automatically by the SDK.

Also available in

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