The specific content to include in a farewell email varies depending on the recipients. An email to coworkers at or near your level should include a friendly message about your experiences with them, while an email to your supervisors should be more professional. Also include personal contact information.
The purpose of a farewell email is to help you maintain relationships with your coworkers once you leave the position. An email to work peers who are not in a position significantly above or below you should begin with a friendly greeting, and proceed to briefly explain why you are leaving the company. Don't focus on too many details, as the purpose is to introduce the information that you are leaving and give them a general idea as to your future. Also include any strong personal memories you have of any individuals or group events, and thank them for the work they did with you. End the email with your personal email address or phone number so that they may reach out to you after you leave the job.
A letter to your supervisors should also be friendly, but take a slightly more professional tone. Thank them for their leadership, and ask if they would be open to talking after you leave so that you may continue to learn from them. In both cases, refrain from speaking ill about the company or any person.