add email testing cases and fix bugs