Short and sweet is the best.
The last thing you want to do is give a candidate false hope.
Dear mr x
Thank you for applying to [company name] for the position of [position]. Unfortunately, we have selected another candidate. Thank you for your interest in [company name]. We will keep your resume on file should another position become available.
Don't mince words.