A dealer arranged drug deals to a prison inmate who had a mobile phone with him behind bars.
Derek Bell, 26, was caught out when police found tell-tale texts that had been sent from his phone to a contact listed as "Shane jail".
Newcastle Crown Court heard one of the messages said drugs would help the prisoner have a "proper chill".
Bell's phone, which was seized when his home was raided, also contained evidence of him supplying cannabis to a group of his friends.
A small number of class C drugs were found during the police search.
Bell, of Southwick Road, Sunderland, admitted supplying cannabis to a circle of 12 pals and supplying class c drugs, including diazepam and subutex, to the inmate.
Prosecutor Neil Pallister told the court: "He accepted dealing to good friends and or associates.
"He accepted being involved, being concerned in the supply of three class c drugs to a male called Shane, referred to in text messages as Shane jail.
"He accepts he was texting Shane, who was in jail.
"He knew the phone number of Shane's mobile phone, which clearly that person had illegally held in prison."
The court heard one text message from Bell to the inmate said "I got you a little joint of dope as well, hid in with them, so you can have a proper chill."
During another conversation, involving quantities and cost, the prisoner said "I'm a bit short until I get a visit".
In other messages, the pals appeared to chat as normal, with the inmate asking Bell "you getting up to much?"
Judge Stephen Earl jailed Bell for 18 months.
The judge said: "You were supplying, via a telephone network.
"People knew to come to you, and come to you they did, on a fairly regular basis, it would seem.
"Clearly, you were having contact with someone from prison.
"It is not just supplying to friends and colleagues but one of whom, at the very least, was in custody.
"Supply into prison is a major aggravating feature in relation to this case.
"This is one of the worst cases you are likely to see in relation to supply of class c drugs."
Alec Burns, defending, said Bell got addicted to diazepam after being prescribed it legitimately then went on to "self medicate" and has since taken steps to combat his problem.
Mr Burns said Bell has family responsibilities which mean others will suffer while he is behind bars.
Mr Burns added: "He was supplying to someone else who might take hem into prison. In fact we don't know if they ever were taken into prison.
"He simply didn't understand how serious the supply of these drugs is considered by the courts.
"He didn't even think about it in that way."