accounts API
The accounts API provides access to the user’s server accounts.
Permissions
See your mail accounts, their identities and their folders
Functions
get(accountId, [includeSubFolders])
Returns details of the requested account, or null if it doesn’t exist.
Parameters
[includeSubFolders
]
(boolean, optional)
– [Added in TB 91]
Specifies whether the MailFolder in the rootFolder property of the returned MailAccount should populate its subFolders property, and include all (nested!) subfolders. This also affects the deprecated folders property of the returned MailAccount. Defaults to true.
Return type (Promise)
MailAccount or null
Required permissions
getDefault([includeSubFolders])
– [Added in TB 85, backported to TB 78.7.0]
Returns the default account, or null if it is not defined.
Parameters
[includeSubFolders
]
(boolean, optional)
– [Added in TB 91]
Specifies whether the MailFolder in the rootFolder property of the default MailAccount should populate its subFolders property, and include all (nested!) subfolders. This also affects the deprecated folders property of the default MailAccount. Defaults to true
Return type (Promise)
MailAccount or null
Required permissions
getDefaultIdentity(accountId)
Returns the default identity for an account, or null if it is not defined.
Parameters
Return type (Promise)
MailIdentity or null
Required permissions
list([includeSubFolders])
Returns all mail accounts. They will be returned in the same order as used in Thunderbird’s folder pane.
Parameters
[includeSubFolders
]
(boolean, optional)
– [Added in TB 91]
Specifies whether the MailFolder in the rootFolder property of each found MailAccount should populate its subFolders property, and include all (nested!) subfolders. This also affects the deprecated folders property of each found MailAccount. Defaults to true.
Return type (Promise)
array of MailAccount
Required permissions
setDefaultIdentity(accountId, identityId)
Sets the default identity for an account.
Required permissions
Events
onCreated
– [Added in TB 98]
Fired when a new account has been created.
Parameters for onCreated.addListener(listener)
listener(accountId, account)
A function that will be called when this event occurs.
Required permissions
onDeleted
– [Added in TB 98]
Fired when an account has been removed.
Parameters for onDeleted.addListener(listener)
listener(accountId)
A function that will be called when this event occurs.
Parameters passed to the listener function
Required permissions
onUpdated
– [Added in TB 98]
Fired when a property of an account has been modified. Folders and identities of accounts are not monitored by this event, use the dedicated folder and identity events instead. A changed defaultIdentity is reported only after a different identity has been assigned as default identity, but not after a property of the default identity has been changed.
Parameters for onUpdated.addListener(listener)
listener(accountId, changedValues)
A function that will be called when this event occurs.
Parameters passed to the listener function
changedValues
(object)
The default identity of this account.
name
(string)
The human-friendly name of this account.
Required permissions
Types
MailAccount
An object describing a mail account, as returned for example by the list([includeSubFolders]) and get(accountId, [includeSubFolders]) methods.
object
The folders for this account. The property may be null, if inclusion of folders had not been requested.
A unique identifier for this account.
The identities associated with this account. The default identity is listed first, others in no particular order.
name
(string)
The human-friendly name of this account.
The root folder associated with this account.
type
(string)
What sort of account this is, e.g. imap, nntp, or pop3.
MailAccountId
A unique id representing a MailAccount.
string
MailAccountType
The type of an account.
string
Supported values:
imap
nntp
none
pop3
Examples
Extracting IMAP accounts
The following code can be used to find all IMAP accounts
// Get all accounts.
let accounts = await messenger.accounts.list();
// Filter on accounts with type "imap".
let imapAccounts = accounts.filter(account => account.type == "imap")