zone-eu / zone-mta

📤 Modern outbound MTA cross platform and extendable server application
European Union Public License 1.2
598 stars 96 forks source link

Modify message and send to specify server #1

Closed ricardopolo closed 8 years ago

ricardopolo commented 8 years ago

We currently have a custom solution that users Haraka and Nodemailer.

I am wondering if this new project can fit better @andris9

These are the basic requirements:

  1. Receive emails and base on some headers DENY or allow the message. So we dont have authentication... is an anonymous MTA but we still need to DENY some messages.
  2. Modify the Headers. Add some, remove some. Did not see if this is posible.
  3. Modify the HTML to insert for example a banner. I can see it can be done. However there are messages that does not have text/html part, just text/plain. Do you handle conversions of that text/plain?
  4. Using some headers and consulting an API we will decide the outbound SMTP server for each message on the fly. Do you allow that kind of setup? I only see routing available as configuration.

Thank you so much Andris!!

andris9 commented 8 years ago

At this point this is not possible and adding support for these actions is not simple either with the current http-based api as making separate http calls for every step (one for auth, one for mail from, one for every text/html node, one for every text/plain, one for message headers etc.) seems like a huge overhead, so I'm thinking about adding some kind of middleware based plugin system like express has.

soncodi commented 8 years ago

@andris9 Haraka has a plugin system that may be useful to take a look at - see https://github.com/haraka/Haraka/tree/master/plugins

ricardopolo commented 8 years ago

I am currently using a Haraka @soncodi but Haraka does not allow to modify the HTML message. I have to compose a new message using mailcomposer and send throught Haraka.

I like this project because it natively allows to modify HTML of a message

andris9 commented 8 years ago

As an update you should be able to do all this with the newly added (and incomplete) plugin system

  1. Add a hook for the 'message:headers' event to check or modify message headers. If you return an error then the message is rejected. See this for example
  2. See 1
  3. Add a rewriter hook for nodes that match your query (eg. content-type must be 'text/html' or 'text/plain'). All message nodes that match this filter are returned as a duplex stream where you can read the current contents of the node and write back the updated contents. See the example here
  4. If you listen for the headers hook (See 1) then nothing is processed until your hook has returned. So you can check the headers and envelope of the message, make some kind of an API request and return an error if you do not want to accept the message
ricardopolo commented 8 years ago

Thanks @andris9

Regarding point 4, after the API request I want to change the smtp server for this message.

This solution is multi tenant and we will select the SMTP server of the customer based of this API request.

andris9 commented 8 years ago

You can override the envelope.sendingZone property inside the headers hook to change the routing for a message. Different sending zones can have different destinations. The default is to send to MX of recipient but a zone can be set up to forward messages to a specific MTA instead (see here).

Keep in mind though that even if it might work, it's still an alpha version and as such might change a lot. So I would not suggest writing your production system on top of ZoneMTA. At least not yet.