So you got rejected from a job, but you got an email from your interviewer telling you that you were great, they loved your resume and interview answers and think you're a perfect match for their company, it's just that they can't find the right position for you. However, they'll keep you in mind for the future. Maybe they even called you to tell you that. They seemed so sincere and actually made the effort to tell you so they must be telling the truth right? Well, there's a chance that it might be the case, but sometimes they are just trying to soften the blow. After all, the firm can't tell you the real reason for not hiring you because the company may get into legal trouble. The risk for them to tell you why you lost out to another candidate is great — you might see it as discrimination.
The best way to find out why you didn't get the job is to do some mock interviewing with your friends or professional contacts. If you're getting all positive feedback and aren't learning anything new, perhaps you need to pick different people to practice with. Try prepping with your best friends, because good pals don't shy away from telling you the truth if it'll help you.