wrote email logic