Write this when someone who you haven't communicated with in a long time writes to you. It's a polite way to show that you're happy to communicate with this person.
For example, imagine that you get an email from a colleague in a different department at work who you last spoke with two weeks ago. You can write back:
It's nice to hear from you.
You can also use this phrase when you're talking on the telephone with someone who you haven't spoken to in a long time.