Fix emails not getting sent in test mode. Closes #1271