extract saveMail function