$emails
Updated on Aug 22, 2025 4 minutes to readThe Email Plugin provides methods to compose, send, and manage emails, as well as access accounts, signatures, templates, and an API client for mailbox operations.
Methods
Method | Description |
---|---|
apiClient | Creates an API client for mailbox operations. |
deleteAccount | Deletes an email account by its identifier. |
findAccountById | Finds an email account by its identifier. |
getAccounts | Retrieves email accounts for a given user. |
Methods Details
apiClient()
• Type
(config: EmailApiClientConfig) => EmailApiClient
• Details
Expects an EmailApiClientConfig object.
Returns an EmailApiClient object.
• Example
// Initialize API client for a specific account
const emailApi = E8App.$emails
.apiClient({ accountId: E8App.vars.account })
.setFolder(E8App.vars.folder);
// 'unread' supports only equal condition, values true | false
emailApi.where({ unread: E8App.vars.unread });
// 'hasAttachments' supports only true condition
if (E8App.vars.hasAttachments) {
emailApi.andWhere({ hasAttachments: true });
}
// 'from' supports only equal condition
if (E8App.vars.from) {
emailApi.andWhere([
'or',
...E8App.vars.from.split(';').map(email => ({ from: email.trim().replaceAll('"', '') })),
]);
}
// 'dateCreated' supports only >= | <= conditions
if (E8App.vars.afterDate) {
emailApi.andWhere(['>=', 'dateCreated', E8App.$timestamp.parse(E8App.vars.afterDate)]);
}
if (E8App.vars.beforeDate) {
emailApi.andWhere(['<=', 'dateCreated', E8App.$timestamp.parse(E8App.vars.beforeDate)]);
}
// 'subject' supports only LIKE condition
if (E8App.vars.subject) {
emailApi.andWhere(['like', 'subject', E8App.vars.subject]);
}
// Recursive function to fetch messages batch by batch
function getBatch(pageToken) {
const batch = emailApi.getMessages(pageToken || null);
// Example output:
// batch.data.values -> array of EmailApiClientMessagesItem
// batch.data.nextPageToken -> string | null
if (batch.data && batch.data.nextPageToken) {
getBatch(batch.data.nextPageToken);
}
}
// Start fetching messages
getBatch(null);
// ----------------------------------------------
// Additional usage examples of EmailApiClient
// ----------------------------------------------
// Initialize another client directly
const client = E8App.$emails.apiClient({
accountId: "12345", // Replace with a real accountId
});
// Example: get list of folders
const folders = client.getFolders();
// Example output:
// folders.data -> array of EmailApiClientFolder
// Example: fetch first page of messages
const messages = client.getMessages(null);
// Example output:
// messages.data.values -> array of EmailApiClientMessagesItem
// messages.data.nextPageToken -> string | null
// Example: get a single message by ID
const message = client.getMessage("abc123");
// Example output:
// message.data -> EmailApiClientMessage
// Example: get attachments for a message
const attachments = client.getAttachments("abc123");
// Example output:
// attachments.data -> array of EmailApiClientAttachment
// Example: mark a message as read
const markResult = client.markMessageAsRead("abc123");
// Example output:
// markResult.isOk -> true/false
// markResult.statusCode -> numeric HTTP-like code
deleteAccount()
• Type
(id: string) => boolean
• Details
Expects a string identifier of the email account.
Returns true
if the account was successfully deleted, otherwise false
.
findAccountById()
• Type
(id: string) => EmailAccount | null
• Details
Expects a string identifier of the email account.
Returns an EmailAccount object or null
if no account is found.
getAccounts()
• Type
(userId: number) => EmailAccount[]
• Details
Expects a numeric user identifier.
Returns an array of EmailAccount objects.