From the sidelines, I'd think the answer is that your email platform should have that feature, or you should consider using entirely separate flows/tools for transactional emails and marketing emails. Not a lawyer, but AFAIK transactional emails are not subject to Spam rules & don't even need to have an "Unsubscribe" link. Mixing the two is just causing yourself needless pain.