Searching Messages
EmailEngine provides powerful search capabilities to find messages across your email accounts. Search queries use IMAP SEARCH syntax under the hood, making them compatible with virtually any email server.
Why Use Search?
Performance
- Server-side filtering reduces data transfer
- Faster than fetching all messages and filtering locally
- Scales to mailboxes with thousands of messages
Flexibility
- Combine multiple criteria
- Search by date ranges, flags, content, headers
- Use complex boolean logic
Efficiency
- Returns only matching messages
- Reduces API calls and processing time
- Lower memory usage
Basic Search
Search by Subject
Find messages with specific subject text:
curl -X POST "https://your-emailengine.com/v1/account/example/search?path=INBOX" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"search": {
"subject": "meeting"
}
}'
JavaScript:
async function searchBySubject(accountId, folderPath, subjectText) {
const response = await fetch(
`https://your-emailengine.com/v1/account/${accountId}/search?path=${folderPath}`,
{
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
search: {
subject: subjectText
}
})
}
);
return await response.json();
}
const results = await searchBySubject('example', 'INBOX', 'meeting');
console.log(`Found ${results.messages.length} messages`);
Search by Sender
Find messages from a specific sender:
async function searchBySender(accountId, folderPath, email) {
const response = await fetch(
`https://your-emailengine.com/v1/account/${accountId}/search?path=${folderPath}`,
{
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
search: {
from: email
}
})
}
);
return await response.json();
}
// Find all emails from john@example.com
const results = await searchBySender('example', 'INBOX', 'john@example.com');