/count
GETGet email counts for all folders including total and unread messages.
GET /api/mail/count
Description
This endpoint retrieves message counts for all folders in the QMail system. For each folder (Inbox, Sent, Drafts, Trash), it returns both the total number of messages and the number of unread messages. Additionally, it provides a summary with overall totals across all folders.
Message Statistics
Use this endpoint to display message counts in your application's UI, such as showing unread badges on folder names or providing an overview of the user's mailbox status.
Interactive API Tester
Try it out
Request
This endpoint does not require any parameters.
Response
Upon success, the endpoint returns a 200 OK response with message counts for each folder and an overall summary.
Response Properties
counts
object
An object containing counts for each folder (inbox, sent, drafts, trash).
summary
object
An object containing overall totals across all folders.
Folder Count Object Properties (inbox, sent, drafts, trash)
total
integer
The total number of messages in the folder.
unread
integer
The number of unread messages in the folder.
Summary Object Properties
total_emails
integer
The total number of messages across all folders.
total_unread
integer
The total number of unread messages across all folders.
Example Response
{
"counts": {
"inbox": {
"total": 42,
"unread": 5
},
"sent": {
"total": 28,
"unread": 0
},
"drafts": {
"total": 3,
"unread": 0
},
"trash": {
"total": 12,
"unread": 1
}
},
"summary": {
"total_emails": 85,
"total_unread": 6
}
}
Examples
JavaScript Example
const apiHost = 'http://localhost:8080';
async function getEmailCounts() {
try {
const response = await fetch(`${apiHost}/api/mail/count`);
const data = await response.json();
console.log('Email Counts:');
console.log(`Inbox: ${data.counts.inbox.total} total, ${data.counts.inbox.unread} unread`);
console.log(`Sent: ${data.counts.sent.total} total, ${data.counts.sent.unread} unread`);
console.log(`Drafts: ${data.counts.drafts.total} total, ${data.counts.drafts.unread} unread`);
console.log(`Trash: ${data.counts.trash.total} total, ${data.counts.trash.unread} unread`);
console.log('');
console.log('Summary:');
console.log(`Total emails: ${data.summary.total_emails}`);
console.log(`Total unread: ${data.summary.total_unread}`);
} catch (error) {
console.error('Error fetching email counts:', error);
}
}
getEmailCounts();
cURL Example
curl -X GET "http://localhost:8080/api/mail/count"
Go Example
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
const apiHost = "http://localhost:8080"
type FolderCount struct {
Total int `json:"total"`
Unread int `json:"unread"`
}
type CountSummary struct {
TotalEmails int `json:"total_emails"`
TotalUnread int `json:"total_unread"`
}
type CountResponse struct {
Counts struct {
Inbox FolderCount `json:"inbox"`
Sent FolderCount `json:"sent"`
Drafts FolderCount `json:"drafts"`
Trash FolderCount `json:"trash"`
} `json:"counts"`
Summary CountSummary `json:"summary"`
}
func main() {
// Make GET request
resp, err := http.Get(fmt.Sprintf("%s/api/mail/count", apiHost))
if err != nil {
panic(err)
}
defer resp.Body.Close()
// Read response
body, _ := ioutil.ReadAll(resp.Body)
var result CountResponse
json.Unmarshal(body, &result)
fmt.Println("Email Counts:")
fmt.Printf("Inbox: %d total, %d unread\n", result.Counts.Inbox.Total, result.Counts.Inbox.Unread)
fmt.Printf("Sent: %d total, %d unread\n", result.Counts.Sent.Total, result.Counts.Sent.Unread)
fmt.Printf("Drafts: %d total, %d unread\n", result.Counts.Drafts.Total, result.Counts.Drafts.Unread)
fmt.Printf("Trash: %d total, %d unread\n", result.Counts.Trash.Total, result.Counts.Trash.Unread)
fmt.Println("")
fmt.Println("Summary:")
fmt.Printf("Total emails: %d\n", result.Summary.TotalEmails)
fmt.Printf("Total unread: %d\n", result.Summary.TotalUnread)
}