Going to Mass is always beneficial. If somebody is really in mortal sin, the Mass should at least help to bring them a little spiritually closer to God so the Holy Spirit can work on them to get them to go to confession.
John may or may not be in mortal sin. He should speak to a priest ASAP. If he is not sure if he can receive Communion, he should not receive until he goes to confession and does whatever else is needed (such as resolving his marital situation) to make sure he gets back in a state of grace. The priest can advise him on what he needs to do.
If John is truly out of the state of grace and in a state of mortal sin, his venial sins will not be forgiven at the Mass. They will be forgiven the next time he makes a good confession. Also if John is truly in a state of mortal sin, he cannot accumulate any merit for attending the Mass.