A man who sent pictures of his ex-wife’s breasts to his mother has narrowly avoided jail.