Fix bug at writeSendEmail function