Code to write a file in case of problems sending email