Mariusz Wojcik took out his manhood and displayed it for all to see during the episode in the town’s Well Street, in June last year.
Paisley Sheriff Court was told that the Crown accepted there was no sexual motivation to his actions which took place during a disturbance there.
In court, the 45-year-old of Paisley, admitted behaving in a threatening or abusive manner likely to cause fear and alarm to others by repeatedly kicking the door of the flat, shouting at the occupants and placing his penis through the letterbox.
He also admitted resisting arrest and hindering and obstructing police who were called to the incident.
The court was told that he did not know those inside - a female, her boyfriend and two younger girls - and had gone to that door in an intoxicated state by chance.
Depute fiscal Pamela Flynn said that the occupants first became aware of a disturbance outside and heard a raised voice which they believed to be Polish.
When Wojcik began to kick the door they became alarmed and called police.
The female had a small child with her as well as her niece.
The male inside the house braced himself behind the door as he feared the accused might manage to kick it in.
As he did so, his girlfriend and her daughter saw the accused push his penis through the letterbox, causing them more alarm.
When officers arrived, they found the accused still present in the close. He was bare-chested and heavily intoxicated.
He lashed out when being arrested.
Defence agent David Nicholson said his client had no recollection of events as he had been so drunk.
“He accepted from the outset that this must have been extremely distressing for those inside and is deeply ashamed of his conduct and apologises,” said the lawyer.
“He did not know those involved - it was a random, spontaneous and impulsive act.”
After hearing that the accused had only recently been made the subject of a community payback order at Glasgow Sheriff Court, Sheriff Seith Ireland, describing the incident as “disgraceful behaviour,” said it would have warranted a jail sentence but he felt it would be best to allow the CPO to get a chance to run.
“Those inside this flat must have been terrified,” he added - “this was quite atrocious conduct.”
Ordering Wojcik to carry out 220 hours of unpaid work, he added: “It is very worrying when so much alcohol is taken that you lost control and became a menace to people at that address with a young child inside.”