fix bugs preventing mails to be sent correctly