I believe it may be worth contacting the manager who provided a bad reference and asking for why they believe you were a bad fit for the position.
You may find that:
- They did not understand the job description and its requirements fully. If you truly believe you're a good fit, it's a possibility, and you can incorporate that somehow into your question. Sometimes this happens. I myself found the lines blurred between frontend/backend software development on a few different openings prior to looking into it more.
- They have some constructive criticism and explanations that will benefit you personally.
- It is possible (though this should be treated with the utmost care and due diligence) that the bad reference was a malicious act. You must absolutely be certain that this is the case. A bad reference rooted in maliciousness and falsehood is illegal. Understand, though, that opinions are protected, and are not necessarily malicious.
This is up to you, but moving forward in the future, you should not use them as a reference again. If I were you, I'd contact my references ahead of time in the future.
Definitely be courteous and polite, and send a thank you letter as you would normally.