Search…
Manage Email Folders & Draft Email
Allow your users the flexibility to manage their inbox with email folders and save draft emails securely
When an email address is provisioned through the Email SDK, a set of standard folders are also created and associated with the provisioned email address. The following table describes the standard folders:
Folder
Function
INBOX
Inbound messages are assigned to the INBOX folder.
SENT
Outbound messages which have completed sending are assigned to the SENT folder.
OUTBOX
Reserved for future use.
TRASH
Messages can be moved to the TRASH folder (this does not permanently delete the message).

Retrieving Email Folders

Email folders associated with an email address are available in the folders attribute of that email address and are retrieved along with the email address.
Email folders associated with an email address can also be retrieved directly through the listEmailFoldersForEmailAddressId method by passing in the id of the email address to query. This returns a ListOutput object with the list of email folder objects which contain information used to identify each folder and to facilitate moving of messages between folders.
The EmailFolder object contains useful information such as the name of the folder, the total size of all messages assigned to the folder and the total count of unseen messages assigned to the folder.
TypeScript
Swift
Kotlin
1
// Obtain the input email address id however makes sense for your implementation.
2
const emailAddressId = emailAddress.id
3
try {
4
const listOutput = await emailClient.listEmailFoldersForEmailAddressId({
5
emailAddressId,
6
cachePolicy: CachePolicy.RemoteOnly,
7
nextToken,
8
})
9
// `listOutput` contains the list of items matching the input.
10
// Page through the results if listOutput.nextToken != undefined.
11
} catch {
12
// Handle/notify user of errors
13
}
Copied!
1
Coming Soon!
Copied!
1
Coming Soon!
Copied!

Move Email Messages between Folders

Email messages can also be moved between folders. For example an email message stored in the "inbox" folder can be moved to the "trash" folder. This is done through the update email messages API as described here. The email message object contains a previousFolderId property which specifies the identifier of the folder that the message was previously in. An example implementation of using the updateEmailMessages method to move a message to another folder is:
Email messages can also be moved between folders. For example an email message stored in the "inbox" folder can be moved to the "trash" folder. This is done through the update email messages API as described here. An example implementation of using the updateEmailMessages method to move a message to another folder is:
TypeScript
Swift
Kotlin
1
// Obtain the input message ids and email address id however makes sense for your implementation.
2
const emailAddressId = emailAddress.id
3
const ids = ['message-id-1', 'message-id-2']
4
try {
5
// List the email folders and find the "trash" folder.
6
const trashFolder = await emailClient.listEmailFoldersForEmailAddressId({
7
emailAddressId,
8
cachePolicy: CachePolicy.RemoteOnly
9
}).then((result) => result.items.find(folder) => folder.folderName === 'TRASH')
10
11
// Update an email message using the "trash" folder id.
12
await emailClient.updateEmailMessages({
13
ids,
14
values: { folderId: trashFolder.id },
15
})
16
// Each of the input messages should now be assigned to the "trash" folder.
17
} catch {
18
// Handle/notify user of errors
19
}
Copied!
1
Coming Soon!
Copied!
1
Coming Soon!
Copied!

Draft Email Messages

The Email SDK also supports the notion of draft email messages. A separate set of APIs are available to handle the lifecycle of drafts.

Creating a Draft Email Message

To create and save a draft email message, call the createDraftEmailMessage method. This method takes in a rfc822Data input property which contains the email message content formatted under RFC 822 as well as the senderEmailAddressId input property which must match the identifier of the email addess from the from field in the RFC 822 data. A call to this method returns metadata of the saved draft. Draft email message data provides the ID of the draft and an updatedAt timestamp representing the last time the draft was saved.
TypeScript
Swift
Kotlin
1
// Obtain the input RFC 822 data and sender email address id however makes sense for your implementation.
2
const rfc822Data: ArrayBuffer = // ...
3
const senderEmailAddressId = senderEmailAddress.id
4
try {
5
const draftMetadata = await emailClient.createDraftEmailMessage({
6
rfc822Data,
7
senderEmailAddressId,
8
})
9
// `draftMetadata` is the metadata associated with the saved
10
// draft email message including the id you can use this to access or
11
// update the draft.
12
} catch {
13
// Handle/notify user of errors
14
}
Copied!
1
Coming Soon!
Copied!
1
Coming Soon!
Copied!

Updating a Draft Email Message

Use the updateDraftEmailMessage method to update a previously created and saved draft email message. The input requires the id of the previously saved draft to perform the update. It is a requirement that the entire message content be replaced with an updated version as part of the rfc822Data input property. A call to this method returns the id of the draft that was updated which should match the id provided in the input.
TypeScript
Swift
Kotlin
1
// Obtain the input RFC 822 data, sender email address id and existing draft id however makes sense for your implementation.
2
const id: string = // ...
3
const rfc822Data: ArrayBuffer = // ...
4
const senderEmailAddressId = senderEmailAddress.id
5
try {
6
const draftMetadata = await emailClient.updateDraftEmailMessage({
7
id,
8
rfc822Data,
9
senderEmailAddressId,
10
})
11
// `draftMetadata` is the metadata associated with the saved
12
// draft email message including the id you can use this to access or
13
// update the draft.
14
} catch {
15
// Handle/notify user of errors
16
}
Copied!
1
Coming Soon!
Copied!
1
Coming Soon!
Copied!

Deleting Draft Email Messages

Draft email messages can be deleted in batches using the deleteDraftEmailMessages method by passing in one or more draft message identifiers and the id of the email address associated with the drafts.
Draft email messages that have been deleted will no longer be available and all traces of the message data and metadata will be deleted permanently.
Draft email messages can only be deleted in batches of 10. Supplying identifiers to the input which exceed this limit will return a LimitExceededError.
A BatchOperationResult type is returned from this method call which contains the status of the batch delete operation. Three possible statuses can be returned:
Status
Definition
Success
All of the draft email messages succeeded to delete.
Partial
Only a subset of draft email messages succeeded to delete. The return object will include a list of identifiers of draft messages which failed the delete and a list which succeeded the delete.
Failure
All of the draft email messages failed to delete.
TypeScript
Swift
Kotlin
1
// Obtain the input draft message ids and email address id however makes sense for your implementation.
2
const ids = ['draft-msg-id-1', 'draft-msg-id-2']
3
const emailAddressId = emailAddress.id
4
try {
5
const deleteResult = await emailClient.deleteDraftEmailMessages({
6
ids,
7
emailAddressId,
8
})
9
// `deleteResult` contains the status of the batch delete operation.
10
} catch {
11
// Handle/notify user of errors
12
}
Copied!
1
Coming Soon!
Copied!
1
Coming Soon!
Copied!

Retrieving Draft Email Messages

Draft email messages can be accessed using its identifier or by querying for a list of its identifiers.
If a draft email message has been deleted, it will no longer be available for access.

Single Draft Email Message by Id

To retrieve a single draft email message, use the getDraftEmailMessage method. This method takes in the id of the draft to retrieve as well as the id of the email address that is associated with the draft. This method returns the draft email message data if it exists.
TypeScript
Swift
Kotlin
1
// Obtain the input email address id and draft id however makes sense for
2
// your implementation.
3
const emailAddressId = emailAddress.id
4
try {
5
const draftMessage = await emailClient.getDraftEmailMessage({
6
id,
7
emailAddressId,
8
})
9
// `draftMessage` containing draft message data and `updatedAt` timestamp
10
// will be returned if a draft message corresponding to `id` is found,
11
// else `undefined`.
12
} catch {
13
// Handle/notify user of errors
14
}
Copied!
1
Coming Soon!
Copied!
1
Coming Soon!
Copied!

List of Draft Email Message Metadata

Use listDraftEmailMessageMetadata to retrieve a list of all the metadata of the draft email messages associated with an email address. The metadata returned in the list can be used to retrieve individual draft email message content, perform an update to an already saved draft, or identify which drafts to perform full retrieval of based on updatedAt timestamp.
TypeScript
Swift
Kotlin
1
// Obtain the input email address id however makes sense for your implementation.
2
const emailAddressId = emailAddress.id
3
try {
4
const draftMetadata = await emailClient.listDraftEmailMessageIds(
5
emailAddressId
6
)
7
// `draftMetadata` is a list of all of the draft email messages'
8
// metadata.
9
} catch {
10
// Handle/notify user of errors
11
}
Copied!
1
Coming Soon!
Copied!
1
Coming Soon!
Copied!

List of Draft Email Message Ids

Use listDraftEmailMessageIds to retrieve a list of all the identifiers of the draft email messages associated with an email address. The identifiers returned in the list can be used to retrieve individual draft email message content or perform an update to an already saved draft.
TypeScript
Swift
Kotlin
1
// Obtain the input email address id however makes sense for your implementation.
2
const emailAddressId = emailAddress.id
3
try {
4
const draftIds = await emailClient.listDraftEmailMessageIds(
5
emailAddressId
6
)
7
// `draftIds` contains a list of all of the draft email message ids.
8
} catch {
9
// Handle/notify user of errors
10
}
Copied!
1
Coming Soon!
Copied!
1
Coming Soon!
Copied!