Hi: x?x
Thank you so much for attending the interview with XX you have done really well and it was a very close call but XX decided to hire an internal candidate who already has the xx knowledge. She found the decision hard as she really liked you as a candidate.
If that is ok with you I will contact you if something else comes in.
Thank you for your time and I hope we can speak together again, thanks.