Improvements #12664
openWt::Mail::Client::send always fails after trying to send to an invalid email address
0%
Description
Trying to send to an invalid email address may result in receiving a SMTP 501 response. Wt spawns the following error message:
Mail.Client: Unexpected response 501
failIfReplyCodeNot also throws an exception, which is catched by the send function, but this function closes the socket when catching an exception. As a consequence, all subsequent send messages fail with the following error:
Mail.Client: Can't send message: not connected
Is it necessary to close the connection when a unexpected response is received?
Or can we automatically reconnect?
Or can we expose the connection status (e.g. add a Wt::Client::isConnected method), in order the caller can at least determine whether is should reconnect?
Or should the caller always assumes the connection is disconnected when sending fails? If so, shouldn't this be documented?
Updated by Matthias Van Ceulebroeck 18 days ago
- Tracker changed from Bug to Improvements
- Target version set to 4.13.2
Hey Dries,
I think the socket is always closed, to ensure that we wouldn't reach a bad state. If the connection/socket is somehow messed up, one could get a variety of AsioWrapper::error_codes. To avoid this, and handling these cases, the client handles the socket "defensively", closing it on any error.
I agree though, then that developers should be able to query the state. So adding a bool Wt::Mail::Client::isConnected() seems like a good idea.
I think often I see people just creating a client in a local scope, using it and then discarding it. So it essentially is often used as a "use-once" class.