It's hard to say why it doesn't work for you without your smtp related code.
Port 465 uses SSL, but port 587 uses STARTTLS. They're different, and you must adjust your code to perform STARTTLS connection or SSL connection.
The main difference is, STARTTLS is a SMTP command you should execute after connection is established, then session is secure.
But with SSL, you have to establish a secure connection first, then execute all other SMTP commands.
I don't know which programming language you're using to write your application, so let me take Python for example here.
In Python smtplib module, there's a class "smtplib.SMTP_SSL" for SSL connection, and function "SMTP.starttls()" for STARTTLS connection.
As described in the module document:
SMTP_SSL should be used for situations where SSL is required from the beginning of the connection and using starttls() is not appropriate.
And you cannot use them the same way. Here's simple example:
# SSL connection.
server = smtplib.SMTP_SSL('localhost') # It uses port 465 by default.
# STARTTLS connection.
server = smtplib.SMTP('localhost')
server.starttls() # This is a SMTP command.
Hope it helps.