Dear ....
(job title) vacancy
Thank you for applying for the vacancy (above/for ....).
(Or - Thank you or attending the interview for the vacancy [above/for ....] on [date].)
I am sorry that on this occasion you have not been successful, (despite presenting yourself very well).
(If you have no objection we will keep your details on file for possible future reference.)
(When we receive a particularly good application that is not successful - as yours is - we offer to give the applicant some constructive feedback about their application, and we would like to make this offer to you. If you'd like this to happen please let us know by (phoning/writing/emailing - as appropriate) and we will be in touch.
I wish you all the best for the future.
Yours sincerely, etc.