Change how the mail connection is closed when the network connection
fails to avoid a deadlock encountered during testing.

Related to, but still does not fix, InvictusInnovations/keyhotee#343