For a more robust and secure email solution, modernizing your application and migrating to Google's Gmail API is highly recommended. Utilizing a library like MailKit can simplify this process.
https://developers.google.com/workspace/gmail/api/guides
To effectively troubleshoot the current connection problem, the error message is crucial. If you don't have it, adding logging and exception handling will help us trace the application's behavior. Additionally, the use of SSL port 465 is problematic as SSL is outdated and vulnerable. Try switching to port 587, which uses the modern and secure TLS protocol. Finally, Google's 'less secure apps access' is being deprecated; App Passwords are the recommended alternative for secure access but this might not be effective for an app to app connection.
https://support.google.com/mail/answer/185833?hl=en#zippy=%2Cwhy-you-may-need-an-app-password