The first thing is to sleep before sending any email back to the person who rejected you. Take some time to breathe and have someone you trust give any draft you write a read through before sending. It never helps to go negative.
Afterward, I take the time to mourn and process the rejection. It sucks and that's very human. I've been rejected more times than I can count, and at times, I was overly confident that a job was going to be mine during the interviews.
I've learned to keep going and put myself out there over and over regardless of what happens. I'm doing this right now for a job that's really calling me, like one of those 'I don't want to wake up at 60 with regret if I don't at least try.' You miss 100% of the shots you don't take.