Send the response to the same person who you had been communicating with until now. What has likely happened here is the HR person submitted the "Reject" decision to a tool, which sent out an auto-generated email.
Keep the response short and to the point. Thank them for the opportunity and mention one (or at most two) interesting things you learned about the company from the interview. You may also express your interest in being contacted for any future opportunities (assuming you are interested, of course).
I have received an email stating that my job application for Senior Engineer has been rejected. I would like to thank you and everyone who interviewed me for their time. I was amazed to learn that Acme Corporation manufactures the world's best Roadrunner catching contraptions.
I look forward to opportunities to work with Acme Corporation in the future.
An additional benefit of sending this response is if the rejection mail was sent in error, and you are still in consideration, the HR person can fix the miscommunication.