Changed mailer to be standalone function