If your iCloud account is not connected ( just an example ) , open mail application click on I cloud and send a mail from - iCloud address ( in To - field type your gmail address ) the mail will be sent to your inbox in your apple mail application a pop up appears .in this screen shot it is showing could not connect to outgoing server , thats the reason when connection doctor is opened SMTP for iCloud is totally vanished .You can apply same with gmail say if IMAP or SMTP is not working . Simply click on always use this server to get joined .
And you will observe all IMAP / SMTP for gmail account and iCloud account are showing green dots and joined to their respective server .
Also if you are using a gmail account now there is no need of typing the port numbers in the fields , it will set up automatically and I am not aware which mail services you are using there is link Mail Settings Lookup - Apple Support
You type the mail address in the field and it will show your correct port settings .
Read this article Get help using iCloud Mail - Apple Support
And the issue you are facing will occur when date and time settings are changed , any read and write permissions in home folder , guest , shared folders also location services should not be altered .
Try these steps otherwise delete the IMAP account if it is used and reconfigure it Add or remove email accounts in Mail on Mac - Apple Support
All of the mails are stored in server they will start syncing , if you are using pop account then the best way is to save mails in V6 folder used in mac os Mojave 10.14 , in Mac OS high Sierra it would be V5 .
Don't use any any anti virus , third party softwares , any kind of third party app that will directly corrupt the apple inbuilt applications and system files .
The last suggestion would be one should create a new test user account if the same issue occurs do not reappear , then switch to a new user test account and transfer the data see this article How to test an issue in another user account on your Mac - Apple Support