The query letter is your chance to pitch your book idea to a literary agent or small press editor. Most major publishing houses require that authors contact them via an agent, while small presses and university presses often are happy to have the author contact them directly. Please remember that for fiction and memoir, agents and editors almost always require that the book is written, edited, and ready to go before you contact them with a query (for some kinds of nonfiction books, this can work differently). Always research the person you're contacting and make sure your query adheres to their specific requests. Some will ask for sample chapters up front. Some won't. Some will prefer to be contacted by email, and some by snail mail. Always address your query to a specific person, by name.
Your query letter should be no more than one page, pristinely edited, and follow a general formula that includes the following things:
These resources go into much more detail on the query letter process.