Yes, it is okay to resign by email but it is always better to resign in person, and then follow up with a formal resignation letter, either by email or hard copy. It is also better to alert your employer that you are resigning email is the best method.