Your script will need to connect as usual using /sockopen and read the server messages in the SOCKREAD event. If the server sends a message that indicates it supports STARTTLS, you can use /sockopen -t at that point in the SOCKREAD event to initiate the negotiation.