Following the comment:
There is also a websocket in Mailpit which broadcasts new messages, although that is not part of the official API as it is intended for the web browser (so it is not documented).
Would you consider it possible to make usage of ws://mailpit/api/events endpoint part of the documentation? Or alternatively introduce a separate websocket endpoint such that could be promoted for public usage in the docs?
For context, here's my use-case. I am using mailpit in a test setup involving docker-compose and playwright. After noticing that Mailpit uses WS for its internal purposes I managed to simplify my "wait for an email to arrive" code to just this:
mailpit_baseurl = "ws://..." // or wss://...
export async function openMailbox(page) {
await page.evaluate((baseurl) => { new WebSocket(`${baseurl}/api/events`) }, mailpit_baseurl);
return page.waitForEvent("websocket");
}
export async function waitForEmail(webSocket) {
const event = await webSocket.waitForEvent("framereceived");
return JSON.parse(event.payload).Data;
}
I find this much cleaner (and potentially more robust) than polling the Mailpit API to see, if the email arrived. However, as it goes with any internal API, depending on it poses a risk this endpoint will be modified without a notice. So, it would be nice to have a "public" form of this endpoint.
Following the comment:
Would you consider it possible to make usage of
ws://mailpit/api/eventsendpoint part of the documentation? Or alternatively introduce a separate websocket endpoint such that could be promoted for public usage in the docs?For context, here's my use-case. I am using mailpit in a test setup involving docker-compose and playwright. After noticing that Mailpit uses WS for its internal purposes I managed to simplify my "wait for an email to arrive" code to just this:
I find this much cleaner (and potentially more robust) than polling the Mailpit API to see, if the email arrived. However, as it goes with any internal API, depending on it poses a risk this endpoint will be modified without a notice. So, it would be nice to have a "public" form of this endpoint.