axllent / mailpit

An email and SMTP testing tool with API for developers
https://mailpit.axllent.org
MIT License
6.17k stars 153 forks source link

Testing emails fetching with Mailpit #363

Closed jsierp closed 1 month ago

jsierp commented 2 months ago

I have a question about the general plans for Mailpit. In some systems - in my case it's Odoo https://github.com/odoo/odoo) - Mailpit could be a perfect tool for testing the email fetching and not only for catching the emails that are sent out. Odoo has a quite complex configuration for routing the emails fetched from a mailbox to existing documents, creating new objects, triggering actions via emails etc. With the current functionalities I'm already able to conduct such tests - with POP3 + "api/v1/send" endpoint, but it would also be useful to be able to do that from the user interface. So my question is: are you planning to add a possibility in the UI to send emails "to mailpit"/reply to emails caught by mailpit, with some possibilities for adjusting headers etc. to be able to simulate fetching an arbitrary email from a usual mailbox? If not, I'm planning to implement something like this myself anyway, would you consider merging such features to Mailpit at all?

axllent commented 2 months ago

Hi @jsierp. I have just completed a > 30h trip to arrive in a time zone that's 10h ahead of my normal time zone, so my brain is a little foggy at the moment as day is night, night is day etc - please excuse any stupid questions from me as I'm easily confused right now.... :) I just wanted to respond to your message so you did not think I was ignoring you.

I'm not following your questions entirely:

  1. You would like the ability to send emails directly to Mailpit using the web UI which would then use the api/v1/send endpoint (to send a reply back to Mailpit?)
  2. You would like the ability to reply to existing emails within Mailpit, but have the ability to adjust the headers before sending
  3. You would like to simulate fetching emails from a remote mailbox

Before I can begin to answer this, I just want to make sure I understand what it is you are actually trying to do here (ie: your exact use-case), and how it would benefit anyone (else) to add & maintain this functionality directly within Mailpit.

Regarding points 1 & 2 above: HTTP APIs for sending mail are in comparison very simplistic alternatives to pre-generating emails via an actual email client (think of an array of headers, multi-part bodies in addition to plain text & HTML, inline attachments vs regular attachments, attachment IDs, etc) , so I suspect you will never achieve what you are explaining with full support.

Regarding point 3: I don't understand this requirement at all.

jsierp commented 2 months ago

Hi @axllent, sorry for my previous description - I was in a hurry :)

Here are my most common scenarios, which cover 99% of the cases that I (and the entire Odoo community) sometimes manually test:

  1. Fetching an email via POP3/SMTP and verifying that the correct actions/records are created in the system. For example, a system administrator wants to configure Odoo to fetch emails from help@example.com and create a Helpdesk Ticket for each fetched email. We would first test this in the staging system, so a "fake/test" email server would be useful.
  2. A salesperson sends a quotation email from Odoo to a customer. When the customer replies, the quotation status should automatically update in Odoo. The email sent from Odoo would have the "Reply-To" header set to, for example, "replies@example.com", and Odoo would use the "In-Reply-To" header to properly route the email and apply the necessary actions.

I understand that Mailpit wasn’t originally designed for these scenarios, but it accidentally fulfills them. Here’s how I’m currently handling it:

  1. I'm using the "api/v1/send" endpoint with Postman to send an email to Mailpit (with the help@example.com in the "To" header). Next, this email is fetched by Odoo using POP3 and the appropriate record is created.
  2. I send an email from Odoo related to a quotation, e.g., Q/2024/0001. Odoo sets the "Reply-To" header to "replies@example.com" and the "Message-Id" includes the ID of Q/2024/0001. Next, I use Postman to send a reply email to Mailpit via the "api/v1/send" endpoint, setting the "In-Reply-To" header to match the "Message-Id" of the original email. Odoo fetches the reply from Mailpit, attaches the message to Q/2024/0001, and triggers additional actions.

What I would like to achieve is performing steps 1 and 2 without relying on Postman, making it easier for non-technical people to run these tests or demonstrations. Again, I understand that this isn’t the purpose for which Mailpit was designed, and your point about the simplicity of its HTTP APIs is valid, but in our case, they are sufficient.

If you know of any better alternatives for achieving points 1 and 2, feel free to share them. However, for us, it’s very convenient to use a single tool, and Mailpit is already quite powerful :)

axllent commented 2 months ago

Thank @jsierp - that makes far more sense to me (plus my brain is working a little better after a few days adjusting to the timezone) :) I'm just about to head away somewhere for the weekend, meaning I won't be able to respond for a few days (just so you know...).

If I understand correctly, you are using Mailpit as the SMTP & POP3 for both the client and the Odoo, and Odoo can differentiate between messages in POP3 (ie: it only processes mail sent to certain addresses)?

To replace postman here you would in fact need a UI that could be somewhat configurable which in turn would send via the HTTP API. I actually created a basic one when I wrote the HTTP send API, so that may help you a bit at this stage (mailpit-send.html.zip). Is this in line with what you were thinking? It (currently) does not allow you to set arbitrary headers (like message IDs etc), nor is it possible to "inherit" values from anything else (pre-set them), but I suspect it is similar to what you were wanting, and possibly a good starting point.

But - the question here is whether something like this should be included within Mailpit or a stand-alone "app" (I'm not saying no, just thinking out loud), and if so, what functionality should it include, and how/where would it be integrated.

I'll leave this with you to think about now as I need to get going.

jsierp commented 2 months ago

Odoo can differentiate between messages in POP3

Yes, it can differentiate between the messages and process mails sent to certain addresses.

Thank you for the send form, it will be a good starting point. I'll come back when I have some more detailed idea about how the functionality could look like.

github-actions[bot] commented 1 month ago

This issue has been marked as stale because it has been open for 7 days with no activity.

github-actions[bot] commented 1 month ago

This issue was closed because there has been no activity since being marked as stale.