mail function complete