There is absolutely no way to do this correctly in general.
However, you can use the tables of common mail providers to fill in the default values, and you can fill in smtp.example.com, etc .... but it will still be inoperable in some simple cases, although, like my working system, where everything is on mail.wherever.com on unusual port numbers. Therefore, in the end, the user should be able to redefine everything that you do.
If you really want it to be shared, you will also have to deal with certificates and EAP.
source share