Lee Markham, 35, pleaded guilty to attempted robbery when he appeared at Preston Crown Court.
The court heard at the time of the offence, Markham, of Latham Street, Avenham, had a £20 a day heroin addiction.
At around 11.25am on August 3 he spotted William Bevan, a sales assistant, withdrawing £50 from the post office in Meadow Street.
As the cash was dispensed, Markham reached over Mr Bevan’s shoulder and attempted to snatch the money.
Karen Brooks, prosecuting, said: “(Mr Bevan) had hold of the money tightly. He had his wallet in his other hand.
“He saw the defendant’s hand and arm trying to grab the money from over his shoulder.”
She said Markham was pushing and jostling against Mr Bevan’s back but as the man resisted the would-be robber ran away.
The incident was captured on CCTV and Markham was identified by a police officer.
He immediately admitted the offence and said he had committed it out of desparation as he had not taken any drugs or medication for two days and was suffering withdrawal symptoms.
He told officers he felt immediately ashamed of what he had done and “deserved to go to prison for a long time.”
Adrian Williams, defending, said Markham has a history of mental health problems and has at times self-medicated with heroin. However he has engaged with the appropriate services in the past and while in prison on remand has managed to detox, admitting he needs to address his drug and health issues separately.
Recorder Christopher Melton QC, handed Markham an 18 month community order with supervision and a drug rehabilitation requirement. He told him: “I am just about persuaded there is a remote chance you may be able to get off drugs. Weighing in the balance a sentence of two months to be served or a lengthier community order I am satisfied that even though the custody threshold has been crossed a community order is the more appropriate sentence.”
Markham must pay a £60 surcharge and be subject to monthly crown court checks.