A prison maths teacher who smuggled codeine into jail for an inmate she was having a relationship with was caught when a love letter was discovered in her handbag, a court heard.