implemented writing to csv file, attach to email and send email