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?

>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.

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.) 

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!

[1] 
https://palant.info/2023/03/08/converting-incoming-emails-on-the-fly-with-opensmtpd-filters/

Reply via email to