email logic