Fixes bug 814647 - Added a test to verify an email cannot be sent twice, fixed a few issues.