Fix database offline mode
Improve testing of emails

Make sure we test that everything which should send email does
and that we clear the pending emails afterwards.