more bug fixes , complete send mail function