$emails
Updated on Aug 22, 2025 6 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. |
create | Opens a compose dialog to create and save an email. |
getAccounts | Retrieves available email accounts. |
getDefaultAccount | Returns the default email account if configured. |
getSignatures | Retrieves stored email signatures. |
getTemplates | Retrieves stored email templates. |
send | Sends an email using the provided configuration. |
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.trim().replaceAll('"', ''));
// 'unread' supports only equal condition, values true | false
// Alternative syntax: ['=', 'unread', true | false]
emailApi.where({ unread: E8App.vars.unread });
// 'hasAttachments' supports only true condition
// Alternative syntax: ['=', 'hasAttachments', true]
if (E8App.vars.hasAttachments) {
emailApi.andWhere({ hasAttachments: true });
}
// 'from' supports only equal condition
// Alternative syntax: ['=', 'from', 'your email']
// Multiple senders supported with 'or'
if (E8App.vars.from) {
emailApi.andWhere([
'or',
...E8App.vars.from.split(';').map(email => ({ from: email.trim().replaceAll('"', '') })),
]);
}
// 'dateCreated' supports only >= | <= conditions
// Timestamp is in UTC, filter applies only by date (time ignored)
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
const getBatch = (pageToken) => {
emailApi
.getMessages(pageToken || null)
.then(batch => {
console.log("Messages:", batch.values);
// Continue loading next page if available
if (batch.nextPageToken) {
getBatch(batch.nextPageToken);
}
})
.catch(e => {
console.error("Error fetching messages:", e.message);
});
};
// Start fetching messages
getBatch();
// ----------------------------------------------
// 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
client.getFolders().then(folders => {
console.log("Folders:", folders);
});
// Example: fetch first page of messages
client.getMessages(null).then(messages => {
console.log("Messages:", messages.values);
});
// Example: get a single message by ID
client.getMessage("abc123").then(message => {
console.log("Message:", message);
});
// Example: get attachments for a message
client.getAttachments("abc123").then(attachments => {
console.log("Attachments:", attachments);
});
// Example: mark a message as read
client.markMessageAsRead("abc123").then(() => {
console.log("Message marked as read");
});
create()
• Type
(
config: EmailConfig,
scriptAlias: E8ScriptAlias,
objectId: E8ObjectId
) => Promise<Email>
• Details
Expects an EmailConfig object, a script alias, and an object identifier.
Returns a Promise that resolves with an Email object.
• Example
E8App.$emails.create(
{
accountId: E8App.vars.defaultAccount,
to: 'email@email.com',
subject: 'Business',
body: 'Hello...',
attachments: []
},
'lstInvoices',
1
);
getAccounts()
• Type
() => Promise<EmailAccount[]>
• Details
Returns a Promise that resolves with an array of EmailAccount objects.
getDefaultAccount()
• Type
() => Promise<EmailAccount | null>
• Details
Returns a Promise that resolves with an EmailAccount object or null
if none is configured.
getSignatures()
• Type
() => Promise<EmailSignature[]>
• Details
Returns a Promise that resolves with an array of EmailSignature objects.
getTemplates()
• Type
() => Promise<EmailTemplate[]>
• Details
Returns a Promise that resolves with an array of EmailTemplate objects.
send()
• Type
(
config: EmailConfig,
scriptAlias: E8ScriptAlias,
objectId: E8ObjectId
) => Promise<Email>
• Details
Expects an EmailConfig object, a script alias, and an object identifier.
Returns a Promise that resolves with an Email object.