May 18, 2023 4:45 PM, "Pēteris Caune" <[email protected]> wrote:
> Hello, > Hello, > Is it possible to configure OpenSMTPD in some way so that it would grab a > specific header from an > email message, and use it in the MAIL FROM field? > Nope, not doable but that's because DATA which contains the headers is emitted by the client AFTER that MAIL FROM and RCPT TO are both accepted, so it's already too late to rewrite them. > From reading the smtpd-filters man page, and the palant.info article [1] it > seems that the filter > would first receive the MAIL FROM value and have a chance to rewrite it, and > only afterwards see > the message itself, including its headers. I don't have hands-on experience > with writing filters > yet, so perhaps I'm completely misunderstanding how filters work. > Filters are actually hooks that happen during an SMTP session, so they are triggered as SMTP commands are being received from a client, they allow "man-in-the-middle"-ing sessions as if they were plugged between the client and the server and validating/altering commands in real time. If you _really_ wanted to use headers to alter a MAIL FROM, you would have to actually write an SMTP proxy that sits _before_ the filters so that it buffers the client session then play your updated session to OpenSMTPD. There is no way to do what you want from within a session without some kind of proxy buffering upfront. > For context, what I'm trying to accomplish: > > I have a web app that sends automated notifications to its users, and needs > to handle bounce > messages (to disable future automated notifications when mailboxes disappear, > or users mark email > as spam instead of unsubscribing, etc.) > unsure I understand :-/ > I am currently using a commercial SMTP relay service which supports bounce > notifications via > webhooks: when an email bounces (immediate or delayed bounce), the service > sends a HTTP POST > request to my configured webhook address, with bounce details in the request > body. When sending > email, I can include a specially named header in the messages, and the > webhook callbacks will > contain the value of that custom header. This way, I can associate bounce > notifications with events > in my web app. > > I'm looking into replicating this setup with OpenSMTPD. My idea is to deliver > bounce notifications > to the web app using either a "mda curl -XPOST @- > https://webhook-address-here" action, or a "|curl > -XPOST @- https://webhook-address-here" alias in the aliases table. The > webhook payload would > contain the entire message, and it would be the webhook handler's > responsibility to parse the > delivery report and handle it. > > But I need to pass some custom data from the original message to the bounce > notification, and so > I'm thinking I could rewrite the MAIL FROM address and include the custom > data in there. Ideally, > if feasible, I'd like to make OpenSMTPD do it. Alternatively, I could patch > my web app to put the > custom data in the MAIL FROM address from the very start, when submitting the > message. > > TL;DR: can OpenSMTPD filters rewrite MAIL FROM based on a header of the mail > message? And, related, > does what I'm trying to do here make any sense? Is there a perhaps a simpler > solution that I am not > seeing? > > Thanks! > Sorry, I don't understand the use-case but that's probably because I'm both tired and haven't done much mail in a while :-)
