Do not connection when no emails to send

Little optimisation of sending alerts to users.
Do not connection when no emails to send.
Merge pull request #646 from iVerner/master

Only connect to mail server if there's emails to send