The expression seems from the evidence to have been invented by Americans during the Second World War. At this time, thousands of US servicemen were stationed overseas for long periods; many of them found that absence didn't make the heart grow fonder. The unhappy news was necessarily communicated in a letter. A writer in the Democrat and Chronicle of Rochester, NY, summed it up in August 1945:
"Dear John," the letter began. "I have found someone else whom I think the world of. I think the only way out is for us to get a divorce," it said. They usually began like that, those letters that told of infidelity on the part of the wives of servicemen... The men called them "Dear Johns".
Why Dear John? That isn't entirely clear but a couple of pointers give a plausible basis for it. John was a common generic name for a man at this period (think also of terms like John Doe for an unknown party to a legal action). Such letters were necessarily written in a formal way, since any note of affection would obviously have been out of place. So a serviceman getting a letter from his wife or girlfriend that started so stiffly knew at once that a certain kind of bad news had arrived.