compose API
The compose API first appeared in Thunderbird 67. It allows to interact with the message composition window.
Permissions
Read and modify your email messages as you compose and send them
Save composed email messages as drafts or templates
Send composed email messages on your behalf
Functions
beginNew([messageId], [details])
Open a new message compose window.
Note: The compose format can be set by details.isPlainText
or by specifying only one of details.body
or details.plainTextBody
. Otherwise the default compose format of the selected identity is used.
Note: Specifying details.body
and details.plainTextBody
without also specifying details.isPlainText
threw an exception in Thunderbird up to version 97. Since Thunderbird 98, this combination creates a compose window with the compose format of the selected identity, using the matching details.body
or details.plainTextBody
value.
Note: If no identity is specified, this function is using the default identity and not the identity of the referenced message.
Parameters
[messageId
]
(integer)
– [Added in TB 84, backported to TB 78.7.0]
If specified, the message or template to edit as a new message.
beginReply(messageId, [replyType], [details])
Open a new message compose window replying to a given message.
Note: The compose format can be set by details.isPlainText
or by specifying only one of details.body
or details.plainTextBody
. Otherwise the default compose format of the selected identity is used.
Note: Specifying details.body
and details.plainTextBody
without also specifying details.isPlainText
threw an exception in Thunderbird up to version 97. Since Thunderbird 98, this combination creates a compose window with the compose format of the selected identity, using the matching details.body
or details.plainTextBody
value.
Note: If no identity is specified, this function is using the default identity and not the identity of the referenced message.
Parameters
messageId
(integer)
The message to reply to, as retrieved using other APIs.
[replyType
]
(string)
Supported values:
replyToSender
replyToList
replyToAll
beginForward(messageId, [forwardType], [details])
Open a new message compose window forwarding a given message.
Note: The compose format can be set by details.isPlainText
or by specifying only one of details.body
or details.plainTextBody
. Otherwise the default compose format of the selected identity is used.
Note: Specifying details.body
and details.plainTextBody
without also specifying details.isPlainText
threw an exception in Thunderbird up to version 97. Since Thunderbird 98, this combination creates a compose window with the compose format of the selected identity, using the matching details.body
or details.plainTextBody
value.
Note: If no identity is specified, this function is using the default identity and not the identity of the referenced message.
Parameters
messageId
(integer)
The message to forward, as retrieved using other APIs.
[forwardType
]
(string)
Supported values:
forwardInline
forwardAsAttachment
getComposeDetails(tabId)
– [Added in TB 74]
Fetches the current state of a compose window. Currently only a limited amount of information is available, more will be added in later versions.
Parameters
tabId
(integer)
Return type (Promise)
Required permissions
setComposeDetails(tabId, details)
– [Added in TB 74]
Updates the compose window. Only fields that are to be changed should be specified. Currently only a limited amount of information can be set, more will be added in later versions.
Note: The compose format of an existing compose window cannot be changed. Since Thunderbird 98, setting conflicting values for details.body
, details.plainTextBody
or details.isPlaintext
no longer throw an exception, instead the compose window chooses the matching details.body
or details.plainTextBody
value and ignores the other.
Required permissions
getActiveDictionaries(tabId)
– [Added in TB 102]
Returns a ComposeDictionaries object, listing all installed dictionaries, including the information whether they are currently enabled or not.
Parameters
tabId
(integer)
Return type (Promise)
Required permissions
setActiveDictionaries(tabId, activeDictionaries)
– [Added in TB 102]
Updates the active dictionaries. Throws if the activeDictionaries
array contains unknown or invalid language identifiers.
Parameters
tabId
(integer)
activeDictionaries
(array of string)
Required permissions
listAttachments(tabId)
– [Added in TB 78]
Lists all of the attachments of the message being composed in the specified tab.
Parameters
tabId
(integer)
Return type (Promise)
array of ComposeAttachment
Required permissions
getAttachmentFile(id)
– [Added in TB 98]
Gets the content of a ComposeAttachment as a File object.
Parameters
id
(integer)
The unique identifier for the attachment.
addAttachment(tabId, attachment)
– [Added in TB 78]
Adds an attachment to the message being composed in the specified tab.
Return type (Promise)
Required permissions
updateAttachment(tabId, attachmentId, attachment)
– [Added in TB 78]
Updates the name and/or the content of an attachment in the message being composed in the specified tab. If the specified attachment is a cloud file attachment and the associated provider failed to update the attachment, the function will throw an ExtensionError.
Return type (Promise)
Required permissions
removeAttachment(tabId, attachmentId)
– [Added in TB 78]
Removes an attachment from the message being composed in the specified tab.
Parameters
tabId
(integer)
attachmentId
(integer)
Required permissions
sendMessage(tabId, [options])
– [Added in TB 90]
Sends the message currently being composed. If the send mode is not specified or set to default, the message will be send directly if the user is online and placed in the users outbox otherwise. The returned Promise fulfills once the message has been successfully sent or placed in the user’s outbox. Throws when the send process has been aborted by the user, by an onBeforeSend event or if there has been an error while sending the message to the outgoing mail server.
Parameters
tabId
(integer)
[options
]
(object)
mode
(string)
Supported values:
default
sendNow
sendLater
Return type (Promise)
object
– [Added in TB 102]
Copies of the sent message. The number of created copies depends on the applied file carbon copy configuration (fcc).
mode
(string)
The used send mode.
Supported values:
sendNow
sendLater
[headerMessageId
]
(string)
The header messageId of the outgoing message. Only included for actually sent messages.
Required permissions
saveMessage(tabId, [options])
– [Added in TB 102]
Saves the message currently being composed as a draft or as a template. If the save mode is not specified, the message will be saved as a draft. The returned Promise fulfills once the message has been successfully saved.
Parameters
tabId
(integer)
[options
]
(object)
mode
(string)
Supported values:
draft
template
Return type (Promise)
object
The saved message(s). The number of saved messages depends on the applied file carbon copy configuration (fcc).
mode
(string)
The used save mode.
Supported values:
draft
template
Required permissions
getComposeState(tabId)
– [Added in TB 90]
Returns information about the current state of the message composer.
Parameters
tabId
(integer)
Return type (Promise)
Events
onBeforeSend
– [Added in TB 74]
Fired when a message is about to be sent from the compose window. This is a user input event handler. For asynchronous listeners some restrictions apply.
Parameters for onBeforeSend.addListener(listener)
listener(tab, details)
A function that will be called when this event occurs.
Parameters passed to the listener function
The current state of the compose window. This is functionally the same as calling the getComposeDetails(tabId) function.
Expected return value of the listener function
object
[cancel
]
(boolean)
Cancels the send.
Updates the compose window. This is functionally the same as calling the setComposeDetails(tabId, details) function.
Required permissions
onAfterSend
– [Added in TB 106, backported to TB 102.3.0]
Fired when sending a message succeeded or failed.
Parameters for onAfterSend.addListener(listener)
listener(tab, sendInfo)
A function that will be called when this event occurs.
Parameters passed to the listener function
sendInfo
(object)
Copies of the sent message. The number of created copies depends on the applied file carbon copy configuration (fcc).
mode
(string)
The used send mode.
Supported values:
sendNow
sendLater
[error
]
(string)
An error description, if sending the message failed.
[headerMessageId
]
(string)
The header messageId of the outgoing message. Only included for actually sent messages.
Required permissions
onAfterSave
– [Added in TB 106, backported to TB 102.3.0]
Fired when saving a message as draft or template succeeded or failed.
Parameters for onAfterSave.addListener(listener)
listener(tab, saveInfo)
A function that will be called when this event occurs.
Parameters passed to the listener function
saveInfo
(object)
The saved message(s). The number of saved messages depends on the applied file carbon copy configuration (fcc).
mode
(string)
The used save mode.
Supported values:
draft
template
[error
]
(string)
An error description, if saving the message failed.
Required permissions
onAttachmentAdded
– [Added in TB 78]
Fired when an attachment is added to a message being composed.
Parameters for onAttachmentAdded.addListener(listener)
listener(tab, attachment)
A function that will be called when this event occurs.
Required permissions
onAttachmentRemoved
– [Added in TB 78]
Fired when an attachment is removed from a message being composed.
Parameters for onAttachmentRemoved.addListener(listener)
listener(tab, attachmentId)
A function that will be called when this event occurs.
Required permissions
onIdentityChanged
– [Added in TB 78.0b2]
Fired when the user changes the identity that will be used to send a message being composed.
Parameters for onIdentityChanged.addListener(listener)
listener(tab, identityId)
A function that will be called when this event occurs.
Required permissions
onComposeStateChanged
– [Added in TB 90]
Fired when the state of the message composer changed.
Parameters for onComposeStateChanged.addListener(listener)
listener(tab, state)
A function that will be called when this event occurs.
onActiveDictionariesChanged
– [Added in TB 102]
Fired when one or more dictionaries have been activated or deactivated.
Parameters for onActiveDictionariesChanged.addListener(listener)
listener(tab, dictionaries)
A function that will be called when this event occurs.
Types
ComposeAttachment
– [Added in TB 78]
Represents an attachment in a message being composed.
object
getFile()
(function) Deprecated.
Use getAttachmentFile(id) instead, for example in a backward-compatible drop-in wrapper function:
/**
* Backward-compatible drop-in replacement for the deprecated
* ComposeAttachment.getFile() function. Instead of calling
* attachment.getFile(), call getFile(attachment).
*/
function getFile(attachment) {
let file = "getAttachmentFile" in browser.compose
? messenger.compose.getAttachmentFile(attachment.id)
: attachment.getFile();
return file;
}
id
(integer)
A unique identifier for this attachment.
[name
]
(string)
The name of this attachment, as displayed to the user.
[size
]
(integer)
– [Added in TB 83, backported to TB 78.5.0]
The size in bytes of this attachment. Read-only.
ComposeDetails
Used by various functions to represent the state of a message being composed. Note that functions using this type may have a partial implementation.
object
An additional fcc folder which can be selected while composing the message, an empty string if not used.
[attachVCard
]
(boolean)
– [Added in TB 102]
Whether or not the vCard of the used identity will be attached to the message during send. Note: If the value has not been modified, selecting a different identity will load the default value of the new identity.
[attachments
]
(array of FileAttachment or ComposeAttachment)
– [Added in TB 82, backported to TB 78.4.0]
Only used in the begin* functions. Attachments to add to the message.
[body
]
(string)
The HTML content of the message.
Array of custom headers. Headers will be returned in Http-Header-Case (a.k.a. Train-Case). Set an empty array to clear all custom headers.
[deliveryFormat
]
(string)
– [Added in TB 102]
Defines the mime format of the sent message (ignored on plain text messages). Defaults to auto, which will send html messages as plain text, if they do not include any formatting, and as both otherwise (a multipart/mixed message).
Supported values:
auto
plaintext
html
both
[deliveryStatusNotification
]
(boolean)
– [Added in TB 102]
Let the sender know when the recipient’s server received the message. Not supported by all servers.
Caution: Setting a value for from
does not change the used identity, it overrides the FROM header. Many email servers do not accept emails where the FROM header does not match the sender identity. Must be set to exactly one valid email address.
[identityId
]
(string)
– [Added in TB 76]
The ID of an identity from the accounts API. The settings from the identity will be used in the composed message. If replyTo
is also specified, the replyTo
property of the identity is overridden. The permission is required to include the identityId
.
[isPlainText
]
(boolean)
– [Added in TB 75]
Whether the message is an HTML message or a plain text message.
[newsgroups
]
(string or array of string)
– [Added in TB 74]
[overrideDefaultFcc
]
(boolean)
– [Added in TB 102]
Indicates whether the default fcc setting (defined by the used identity) is being overridden for this message. Setting false will clear the override. Setting true will throw an ExtensionError, if overrideDefaultFccFolder
is not set as well.
This value overrides the default fcc setting (defined by the used identity) for this message only. Either a MailFolder specifying the folder for the copy of the sent message, or an empty string to not save a copy at all.
[plainTextBody
]
(string)
– [Added in TB 75]
The plain text content of the message.
[priority
]
(string)
– [Added in TB 102]
The priority of the message.
Supported values:
lowest
low
normal
high
highest
[relatedMessageId
]
(integer)
– [Added in TB 95]
The id of the original message (in case of draft, template, forward or reply). Read-only. Is null in all other cases or if the original message was opened from file.
[returnReceipt
]
(boolean)
– [Added in TB 102]
Add the Disposition-Notification-To header to the message to requests the recipients email client to send a reply once the message has been received. Recipient server may strip the header and the recipient might ignore the request.
[subject
]
(string)
[type
]
(string)
– [Added in TB 88]
Read-only. The type of the message being composed, depending on how the compose window was opened by the user.
Supported values:
draft
new
redirect
– [Added in TB 90]
reply
forward
ComposeDictionaries
– [Added in TB 102]
A dictionary object with entries for all installed dictionaries, having a language identifier as key (for example en-US) and a boolean expression as value, indicating whether that dictionary is enabled for spellchecking or not.
object
<language identifier>
(boolean)
ComposeRecipient
string
A name and email address in the format Name <email@example.com>, or just an email address.
OR
object
id
(string)
The ID of a contact or mailing list from the contacts API and mailingLists API.
type
(string)
Which sort of object this ID is for.
Supported values:
contact
mailingList
ComposeRecipientList
– [Added in TB 74]
OR
array of ComposeRecipient
ComposeState
– [Added in TB 90]
Represent the state of the message composer.
object
canSendLater
(boolean)
The message can be send later.
canSendNow
(boolean)
The message can be send now.
CustomHeader
A custom header definition.
object
name
(string)
Name of a custom header, must have a X- prefix.
value
(string)
FileAttachment
Object used to add, update or rename an attachment in a message being composed.
object
The new content for the attachment.
[name
]
(string)
The new name for the attachment, as displayed to the user. If not specified, the name of the provided file
object is used.