Migrated email functionality to js file