A prison officer and an inmate who exchanged more than 5,000 Snapchat messages during a secret six-month affair have both been jailed.