[1.5.x] Fixed #19134 -- Allowed closing smtp backend when the server is stopped

Thanks Sebastian Noack for the report and the initial patch.
Backport of 1b3f832ab7 from master.
[1.5.x] Fixed #19382 -- Stopped smtp backend raising exception when already closed

Thanks Sebastian Noack for the report and the initial patch.
Backport of ffa50ca35 from master.