Skip to the documentation
PHP

$client->connectedMailboxes

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

Methods

Mailboxes that stay at Gmail, Yahoo, iCloud or another provider and are worked from Nextmail: find their mail servers, connect one with an app password, see whether it syncs, pause, resume or rename it, give it a new password, sync it now and disconnect it. New mail is copied in, what is done to it here goes back to the provider, and mail written as its address is sent through the provider.

connectedMailboxes->list

List the connected mailboxes

Scopesthreads:read
Signature
list(?string $apiKey = null): array

Returns every mailbox connected to the workspace in one list, newest first. The list comes whole and is never paged. A connected mailbox stays at its provider, such as Gmail or Yahoo, and is worked from Nextmail: its new mail is copied in, what is done to it here goes back to the provider, and mail written as its address is sent through the provider.

status is active while it syncs and sends, paused while a person stopped it, needs-sign-in when the provider stopped accepting its password, and failing when the last five syncs failed and it keeps trying less often.

Parameters

apiKeystring

Overrides the client API key for this call only.

Returns

A list of connected mailbox arrays. Each item has id, addressId, email, label, provider, method, status, pauseReason, lastError, lastSyncedAt, createdAt, connectedBy, username, imap, smtp and historyImportId. imap and smtp are arrays with host, port and security, or null. status, method and pauseReason take the values of ConnectedMailboxStatuses, ConnectedMailboxMethods and ConnectedMailboxPauseReasons in Nextmail\Constants, and provider those of MailboxProviders.

Example

use Nextmail\Constants\ConnectedMailboxStatuses; foreach ($client->connectedMailboxes->list() as $mailbox) {    if ($mailbox['status'] === ConnectedMailboxStatuses::ACTIVE) {        echo $mailbox['email'], ' last synced ', $mailbox['lastSyncedAt'] ?? 'never', PHP_EOL;    } else {        echo $mailbox['email'], ' is ', $mailbox['status'], ': ', $mailbox['lastError'] ?? $mailbox['pauseReason'], PHP_EOL;    }}

Notes

  • A key or an app limited to particular addresses sees only the mailboxes of those addresses.

  • lastError is what the mail server said the last time something went wrong, and null while nothing is wrong. pauseReason says why a mailbox is not active: by-person, sign-in or unreachable.

  • Read only, so the SDK retries it after a network failure like any other read.

Also available in

API
GET /connected-mailboxes
TypeScript
nextmail.connectedMailboxes.list()
Python
connected_mailboxes.list()
Ruby
connected_mailboxes.list
Go
ConnectedMailboxes.List
Java
connectedMailboxes().list
C#
ConnectedMailboxes.ListAsync
CLI
nextmail connected-mailboxes list

connectedMailboxes->get

Read one connected mailbox by id

Scopesthreads:read
Signature
get(string $id, ?string $apiKey = null): array

Looks up one connected mailbox and returns it in the same shape as a row of list: whether it is syncing, when it last finished, and what went wrong if it did not.

Parameters

idstringRequired

Connected mailbox id such as cmb_5c1e9a7b3d2f48e6a0b4c7d1, as list returns it.

apiKeystring

Overrides the client API key for this call only.

Returns

An array with id, addressId, email, label, provider, method, status, pauseReason, lastError, lastSyncedAt, createdAt, connectedBy, username, imap, smtp and historyImportId.

Example

use Nextmail\Constants\ConnectedMailboxStatuses; $mailbox = $client->connectedMailboxes->get('cmb_5c1e9a7b3d2f48e6a0b4c7d1'); if ($mailbox['status'] === ConnectedMailboxStatuses::NEEDS_SIGN_IN) {    echo $mailbox['email'], ' needs a new app password: ', $mailbox['lastError'], PHP_EOL;} else {    echo $mailbox['email'], ' is ', $mailbox['status'], PHP_EOL;}

Notes

  • A missing mailbox, or one whose address the caller cannot reach, throws ApiException with isNotFound() true and code connected_mailbox_not_found.

  • Read only, so the SDK retries it after a network failure like any other read.

Also available in

API
GET /connected-mailboxes/{id}
TypeScript
nextmail.connectedMailboxes.get()
Python
connected_mailboxes.get()
Ruby
connected_mailboxes.get
Go
ConnectedMailboxes.Get
Java
connectedMailboxes().get
C#
ConnectedMailboxes.GetAsync
CLI
nextmail connected-mailboxes get

connectedMailboxes->discover

Find the mail servers for a mailbox

Scopesdomains:write
Signature
discover(string $email, ?string $apiKey = null): array

Looks up where the mailbox behind an address lives and what it signs in with, so the right password can be asked for before connect. Nothing is stored and no sign-in is attempted.

signIn is app-password for Gmail, Yahoo, iCloud and the other providers that want one, password where the everyday password works, and microsoft for Outlook.com and Microsoft 365, which only the Microsoft sign-in in the app can connect. imap is null when nothing was found: pass host to connect. smtp is null when the outgoing server is found while connecting, or can be passed as smtpHost.

Parameters

emailstringRequired

The address of the mailbox.

apiKeystring

Overrides the client API key for this call only.

Returns

An array with object set to connected_mailbox_settings, email, provider, signIn, imap and smtp. imap and smtp are arrays with host, port and security, or null. provider and signIn take the values of MailboxProviders and MailboxSignIns in Nextmail\Constants.

Example

use Nextmail\Constants\MailboxSignIns; $settings = $client->connectedMailboxes->discover('ada@gmail.com'); if ($settings['signIn'] === MailboxSignIns::MICROSOFT) {    echo 'Connect this mailbox with the Microsoft sign-in in the app', PHP_EOL;} elseif ($settings['signIn'] === MailboxSignIns::APP_PASSWORD) {    echo 'Make an app password in the security settings of the ', $settings['provider'], ' account', PHP_EOL;} if ($settings['imap'] === null) {    echo 'Ask for the IMAP host of ', $settings['email'], PHP_EOL;}

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

Also available in

API
GET /connected-mailboxes/settings
TypeScript
nextmail.connectedMailboxes.discover()
Python
connected_mailboxes.discover()
Ruby
connected_mailboxes.discover
Go
ConnectedMailboxes.Discover
Java
connectedMailboxes().discover
C#
ConnectedMailboxes.DiscoverAsync
CLI
nextmail connected-mailboxes discover

connectedMailboxes->connect

Connect a mailbox at another provider

Scopesdomains:write
Signature
connect(array $body, ?string $apiKey = null): array

Connects a mailbox that stays at Gmail, Yahoo, iCloud or another provider, so its address becomes an address of the workspace while its mail stays where it is. It signs in to the incoming and the outgoing server with the password, keeps the password sealed, adds the address and starts copying new mail in within a minute.

From then on read, starred, archived, spam and deleted go back to the provider, and mail written as the address goes out through the provider, so it lands in its Sent folder too. With 'importHistory' => true it also starts an import of the mail already in the mailbox, which imports->get follows by historyImportId.

Most providers want an app password, made in the account's security settings, not the everyday password. Leave host and smtpHost out to have the servers found from the address, as discover shows.

Parameters

emailstringRequired

The address of the mailbox, such as you@gmail.com.

passwordstringRequired

The app password of the mailbox, or its password where the provider has no app passwords.

hoststring

The IMAP server. Left out, it is looked up from the address.

portint

The IMAP port: 993 with TLS, or 143 with STARTTLS.

securitystring

How the IMAP connection is encrypted: tls or starttls, the values of Nextmail\Constants\MailboxSecurities.

usernamestring

The name to sign in with, when it is not the address.

smtpHoststring

The SMTP server mail is sent through. Left out, it is found.

smtpPortint

The SMTP port: 465 with TLS, or 587 with STARTTLS.

smtpSecuritystring

How the SMTP connection is encrypted: tls or starttls, the values of Nextmail\Constants\MailboxSecurities.

labelstring|null

A name for the address, shown beside it in the app, up to 120 characters.

importHistorybool

Whether to copy the mail already in the mailbox as well. Left out, only mail that arrives from now on comes in.

apiKeystring

Overrides the client API key for this call only.

Returns

An array, the connected mailbox with a new id, the addressId the mailbox appears as, and status set to active.

Example

$mailbox = $client->connectedMailboxes->connect([    'email' => 'ada@gmail.com',    'password' => (string) getenv('GMAIL_APP_PASSWORD'),    'label' => 'Ada (Gmail)',    'importHistory' => true,]); echo $mailbox['id'], ' connects ', $mailbox['email'], ' as ', $mailbox['addressId'], ', ', $mailbox['status'], PHP_EOL; if ($mailbox['historyImportId'] !== null) {    echo 'The mail already there comes across in import ', $mailbox['historyImportId'], PHP_EOL;}

Notes

Also available in

API
POST /connected-mailboxes
TypeScript
nextmail.connectedMailboxes.connect()
Python
connected_mailboxes.connect()
Ruby
connected_mailboxes.connect
Go
ConnectedMailboxes.Connect
Java
connectedMailboxes().connect
C#
ConnectedMailboxes.ConnectAsync
CLI
nextmail connected-mailboxes connect

connectedMailboxes->update

Pause, resume or rename a connected mailbox, or give it a new password

Scopesdomains:write
Signature
update(string $id, array $patch, ?string $apiKey = null): array

Changes a connected mailbox and returns it as it is now. Send only what changes: a field left out stays as it is.

'paused' => true stops syncing and sending through the mailbox, and 'paused' => false starts both again. The mail already copied in stays either way. password gives it a new app password after the provider stopped accepting the old one: it is checked against both servers before it is kept, and a mailbox that needed signing in starts syncing again. label renames its address, and null clears the name.

Parameters

idstringRequired

Connected mailbox id such as cmb_5c1e9a7b3d2f48e6a0b4c7d1, as list returns it.

pausedbool

true pauses the mailbox and false resumes it. Left out, it stays as it is.

passwordstring

A new app password. Left out, the password stays.

labelstring|null

A name for the address, up to 120 characters, or null to clear it. Left out, the name stays.

apiKeystring

Overrides the client API key for this call only.

Returns

An array with the unchanged id, and status, pauseReason and label as they are now.

Example

$mailbox = $client->connectedMailboxes->update('cmb_5c1e9a7b3d2f48e6a0b4c7d1', [    'password' => (string) getenv('GMAIL_APP_PASSWORD'),]); echo $mailbox['email'], ' is ', $mailbox['status'], PHP_EOL; $paused = $client->connectedMailboxes->update('cmb_5c1e9a7b3d2f48e6a0b4c7d1', ['paused' => true]); echo $paused['email'], ' is ', $paused['status'], PHP_EOL;

Notes

Also available in

API
PATCH /connected-mailboxes/{id}
TypeScript
nextmail.connectedMailboxes.update()
Python
connected_mailboxes.update()
Ruby
connected_mailboxes.update
Go
ConnectedMailboxes.Update
Java
connectedMailboxes().update
C#
ConnectedMailboxes.UpdateAsync
CLI
nextmail connected-mailboxes update

connectedMailboxes->sync

Sync a connected mailbox now

Scopesthreads:write
Signature
sync(string $id, ?string $apiKey = null): array

Asks for a sync straight away instead of at the next interval, and returns at once with the mailbox. The sync follows within seconds, and lastSyncedAt moves when it has finished.

A mailbox is synced every 30 seconds while mail comes in, and less often after it has been quiet for a while, down to every five minutes. A paused mailbox, or one that needs signing in, is not synced.

Parameters

idstringRequired

Connected mailbox id such as cmb_5c1e9a7b3d2f48e6a0b4c7d1, as list returns it.

apiKeystring

Overrides the client API key for this call only.

Returns

An array, the connected mailbox as it was when the sync was asked for.

Example

$mailbox = $client->connectedMailboxes->sync('cmb_5c1e9a7b3d2f48e6a0b4c7d1'); echo 'Asked ', $mailbox['email'], ' to sync. The last sync finished at ', $mailbox['lastSyncedAt'] ?? 'no time yet', PHP_EOL;

Notes

  • A missing mailbox is a 404 connected_mailbox_not_found.

  • Asking twice does no harm, so the SDK retries this call after a network failure.

Also available in

API
POST /connected-mailboxes/{id}/sync
TypeScript
nextmail.connectedMailboxes.sync()
Python
connected_mailboxes.sync()
Ruby
connected_mailboxes.sync
Go
ConnectedMailboxes.Sync
Java
connectedMailboxes().sync
C#
ConnectedMailboxes.SyncAsync
CLI
nextmail connected-mailboxes sync

connectedMailboxes->disconnect

Disconnect a mailbox

Scopesdomains:write
Signature
disconnect(string $id, ?string $apiKey = null): array

Stops syncing and sending through the mailbox, forgets its password and removes its address from the workspace. The mail already copied in stays in Nextmail, and nothing is changed at the provider. An import of its history that is still running is cancelled.

To stop it for a while and keep it, use update with 'paused' => true. To use it again later, start over with connect.

Parameters

idstringRequired

Connected mailbox id such as cmb_5c1e9a7b3d2f48e6a0b4c7d1, as list returns it.

apiKeystring

Overrides the client API key for this call only.

Returns

An array with object set to connected_mailbox, the id, the addressId it appeared as, its email, and deleted set to true.

Example

$removed = $client->connectedMailboxes->disconnect('cmb_5c1e9a7b3d2f48e6a0b4c7d1'); echo $removed['email'], $removed['deleted'] ? ' is disconnected' : ' is still connected', PHP_EOL;

Notes

Also available in

API
DELETE /connected-mailboxes/{id}
TypeScript
nextmail.connectedMailboxes.disconnect()
Python
connected_mailboxes.disconnect()
Ruby
connected_mailboxes.disconnect
Go
ConnectedMailboxes.Disconnect
Java
connectedMailboxes().disconnect
C#
ConnectedMailboxes.DisconnectAsync
CLI
nextmail connected-mailboxes disconnect