You want to know if the Messaging Gateway can be configured to use port 587 or port 465 because you've been told these ports are used for secure mail delivery.
This is typically a recommendation from an entity that is not aware that the Messaging Gateway is a Mail Transfer Agent appliance used to relay messages between mail servers and is not typically used for end user email client access.
The Messaging Gateway can be configured to accept messages on specific ports and configured to deliver to specific ports, but the situation may not be as simple as that. You may have noticed above that I separated the receiving (listeners) and sending (delivery) aspects, you will need to know which you intend to configure and that also has further considerations.
Port 465 for mail servers is deprecated, as described here:
""smtps" is also the name of an IANA-registered service, with the TCP port number 465. The service was intended for use by Mail Transfer Agents (MTAs), as a point of contact where these could exchange email in an encrypted form rather than in plaintext. The registration was quickly revoked, however, as standardization efforts resulted in an alternate approach. The registration has never been reinstated."
Reference: https://en.wikipedia.org/wiki/SMTPS
Port 587 is typically used for "message submission", which means it is typically used by user facing mail servers such as Exchange or Postfix, the type of mail server you configure your email client (a Message User Agent, Outlook for example) to connect to. These mail servers are called Message Submission Agents. The Messaging Gateway is typically not user facing, it is a Message Transfer Agent meant as a relay between mail servers. The distinctions are discussed in the following RFC:
In general, SMTP delivery between mail servers is still done via port 25, using public key encryption (TLS) and other protocols like DMARC and DNSSEC to secure the mail delivery. Changing the port for acceptance or delivery will impact how you receive and deliver mail since normal mail server delivery attempting to transmit via port 25 will fail.
Messaging Gateway does have an SMTP Authentication feature which uses port 587, but this is a narrow use case. More information on SMTP Authentication can be found in the following documentation link: