Are you good with Python or Ruby?
I’ve done something that sounds very similar to your challenge using Ruby’s NET::IMAP and NET::SMTP classes. These are included in a standard ruby install.
Basically, use the IMAP class to connect to the imap server. You can then iterate over the emails on the server and construct structs that represent the components of the email (from, to, subject, body, etc). You might store those in an array as you construct them.
Once you have constructed the email structs you can iterate over those using the array I mentioned above and run regex against the subject property of each for whatever you are looking for.
In case there match case you might prepare a reply-to email struct which you can set the body to your template email, add the original email address’s from as the to address and then your from address in the from address.
Finally, use the NET::SMTP class to create a connection to you smtp server and send your email.
I typed this on a phone so I can’t be as complete as I’d like. But basically you create a connection to your imap server. Iterate over the emails and create structs out of them. Iterate over those structs’ subject line with regex to match whatever your looking for.
Next, when there’s matches construct email structs which you can send back. So, set the addressing and placing your body template based on the regex match.
Finally, use the smtp lib to connect to your smtp server and send those emails you built.
Good luck. Let me know if you run into any trouble.
https://ruby-doc.org/stdlib-2.6.3/libdoc/net/smtp/rdoc/Net/SMTP.html
https://ruby-doc.org/stdlib-2.6.3/libdoc/net/smtp/rdoc/Net/SMTP.html