Hello LioraB
I think that the best option is to buy the tickets in the SBB Mobile app, you can avoid queues at the Trenitalia ticket office in Milano Centrale. No SBB ticket office is available.
These tickets (Arcobaleno Transfrontaliera) are valid for 4 hours and must not be validated, but you must ask the staff to open the access gates. They are also valid for the funicular between the station and the city or for other public transport in Lugano.
Kind regards
Danhiel