improve mail function