Added error handling to mailer functions