It is quite obvious that this work relationship is rather on the skids here. But I do not see any place here where you have been harassed or mistreated or discriminated against illegally. You have an important client with whom you have frequent contact who is now very unhappy with you. This comes after a long time of you enduring (as you put it) a lot of talk and sexual innuendo, and not making it very clear that it was unwelcome, as you might have done with the very first of this, and nipped it in the bud. Instead, you played along, even emailed back to him in the same vein. He probably thought you were flirting with him, or that his comments and approaches were not unwelcome.
Shed no tears about his telling someone sometime ago that you were gay, either. Gossip speculating about someone's sexuality isn't sacred. and it's not against the law. If you are trying to shock or gain sympathy in your complaints about his emails to you that contain disgusting comments (regardless of sexual orientation,) we just have to remember that this probably happened some time ago, and though you may have saved the emails, you didn't do anything about this or complain to anyone while you were receiving them. I suspect your contact may also have saved the emails you sent him, which you may not be proud of.
So you have a stand off situation. You wish to change the tone of the relationship. So do so, from now on, from your point of view. You don't have to tell him anything, just be polite, professional, and put some distance between the two of you in tone and behavior. If he greets you on the phone with "Hello, you #&$%5#@ you!" you respond with "Hi Jim, it's John here." and move on to business. Be brief. Do not provide him with any extra conversation in which he can get nasty. You should have been doing this all along if you were not enjoying his chats. Yes, it's a good thing to have rapport with your clients, but this was above and beyond the call of duty. Do not argue with him, confront him, or accuse him of trying to get you into trouble. In other words, professionalism, no drama.
If he tries to get you in trouble, tells lies about your performance, let it ride. Do the job to the best of your abilities. If your supervisors ask you about an issue, or give you trouble about your relationship with him, say that you are trying to work with Jim in a more professional way. I advise you to stay away from telling anyone, including your higher ups, about the nasty emails, the buddy buddy relationship or that he's lying about you or telling people you're gay. With this much time since it began, this could be misconstrued as a situation in which you at first welcomed his behavior, until you two had a quarrel of some sort. That's not the impression you want to give, is it?
If you were to quit the job at this point, it does not appear you would not have any legal recourse under EEOC, which is the only venue you'd have to complain, and you wouldn't be very likely to qualify for unemployment insurance. If they fire you, you can file for unemployment benefits while looking for another job. But be sure you do not give them any valid misconduct reason to fire you. Do the job to the best of your abilities always. Stress to everyone that you are doing this. If they fire you they cannot do so without showing they had a valid misconduct reason. Poor performance after over six years would be very hard to defend, if your performance has been up to par before this time. The burden of proof would be on the employer to show this good misconduct reason to fire you or at least you'd probably be able to draw unemployment benefits after you were terminated.
When you quit a job and apply for unemployment, you have to show you had a valid misconduct reason to leave the job and that you had exhausted every legitimate reasonable means to solve the problem before quitting. It doesn't sound much like you've done this. And since the behavior you are complaining about in this client has occurred over a long time period, in which you did not do anything to try to resolve the problem, they'll not be very likely to approve your benefits, unless something really outrageous happens now which forces you to quit suddenly ( like he comes into your place of business and makes an overt harassing move on you). Then you might have some sort of EEOC complaint. It would be helpful if you'd made your employer aware of his previous behavior and they had not tried to help you resolve the conflict.
In unemployment training, this situation is almost the old "my boss slapped my face last April" problem. Yes, a boss slapping his employee isn't appropriate. It would be reasonable grounds to quit the job. But that you continued to work there for a long time afterward, and then quit at a later date, complaining about this particular incident, does not indicate that you considered it unacceptable behavior.
What I'd strongly suggest you do is first of course, work hard to professionalize your relationship with your client. You may find it necessary to discuss the situation, and your relationship with him with your supervisor. Leave out all the gory details and emails, okay? Because you are making yourself look really bad with those. Try to resolve the problem.
In the meantime, I'd also be putting out some feelers toward moving on. This situation may not be solved easily, it may escalate. You need to give yourself plenty of preparation time by finding another position in which you won't have to worry about this. But I'd keep the job I have until I found something else, because at this point, unemployment insurance while you are looking for other jobs isn't much of a prospect, and there's nothing else you could do, nobody to sue, nowhere to complain.