Derek Mackay admits he has "behaved foolishly" after a newspaper reports that he sent 270 messages to a 16-year-old boy.