We use “good afternoon” from 12:01 pm until 5 pm and “good evening” from 5 pm until 10 pm.
Afternoon is the time literally after noon. Noon is at 12 pm in the middle of the day. We wish people a “good afternoon” from 12:01 pm until 5 pm. “Good afternoon” is a greeting in English so if you are unsure what time it is, you can always say “hello”.
Good evening is a little bit more difficult to say exactly what time it starts and ends, You can read more about “good evening” here.
Usually, people say “good evening” around the time the sun is going down.
At 4 pm, you can say good afternoon in an email or in person.
At 5 pm, you can say good evening.
At 6pm, you can also say good evening.
It is not common to say good night in an email unless you are having a back and forth conversation and you want to end the conversation and go to sleep.