fixed bugs in email code (prevent sending a mail every second)