Mail function modified