mirror of
https://github.com/axllent/mailpit.git
synced 2026-04-26 00:35:51 +03:00
[GH-ISSUE #546] Search API returns total count but empty messages array when searching for custom header values #354
Labels
No labels
awaiting feedback
bug
docker
documentation
enhancement
github_actions
invalid
pull-request
question
stale
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/mailpit#354
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @mstroeve on GitHub (Jul 30, 2025).
Original GitHub issue: https://github.com/axllent/mailpit/issues/546
Description
When migrating from Mailhog to Mailpit, we noticed that the search API finds messages (returns correct
totalcount) but returns an emptymessagesarray when searching for specific values in custom headers or message content.Steps to Reproduce
Send an email with a custom header, for example:
Verify the email is received and the header is present:
Search for this header value using the search API:
Expected Behavior
The search API should return the messages array containing the email(s) with the matching header value.
Actual Behavior
The API returns:
Note that
totalis 3 (correct - there are 3 emails with this header), butmessagesis empty.Environment
Use Case
We're using custom headers to filter emails by tenant/site in a multi-tenant application for staging. In Mailhog, we could search for these custom header values to show only emails belonging to a specific tenant. This is critical for our development environment where multiple sites share the same Mailpit instance.
Workaround
Currently, we have to:
/api/v1/messages)/api/v1/message/{ID}/raw)This is inefficient and doesn't scale well.
Additional Context
is:unreadwork correctlyIs this a known limitation or a bug? Any guidance would be appreciated.
@axllent commented on GitHub (Jul 31, 2025):
Hi @mstroeve, thanks for the detailed issue. I'll do my best to answer the various points without dragging it out too much.
The first (and most important) thing to note is that Mailpit's search does not search the entire raw email - it contains an index of some headers (From, To, Cc, Bcc, Subject and Message-ID), and a plain text representation of the HTML content (if it exists) or alternatively the content of the plain/text part if no HTML part exists. It also includes the names (but not contents) of attachments.
The reason it only includes these fields is quite simple: Mailpit uses a sqlite database to store and search messages ,which is fast, lightweight (CPU and RAM), and fairly flexible (not limited to just exact phrases). MailHog, on the other hand, will literally open every message and attempt to match the search phrase against anything in the entire email - which is very inefficient/slow, CPU & memory intensive, and not flexible in terms of searching. So the bottom line is they work very differently.
In your case you're wanting to search the value of a particular custom header which is not included in the search index. What you are trying to do cannot be achieved in this manner.
Actually the
totalis the total number of messages in the database, not the number of messages in the search results (that ismessages_countas per the schema in the API docs ~ you're mixing the two). Mailpit is returning that there are0results in your search, but that there are 3 messages in total in the database (within this tenant).Alternative approach
Given that you cannot search for custom headers, why not try it a different way. You could either:
Message-IDrather than a customX-MailHog-ID- then you can search forhttp://localhost:8025/api/v1/search?query=message-id:<your-id>X-Tags: <your-id>header and then filter by that taghttp://localhost:8025/api/v1/search?query=tag:<your-id>Both of these options would get you where you need to be. Hope this helps?
@github-actions[bot] commented on GitHub (Aug 8, 2025):
This issue has been marked as stale because it has been open for 7 days with no activity.
@github-actions[bot] commented on GitHub (Aug 11, 2025):
This issue was closed because there has been no activity since being marked as stale.