Washington (CNN) -- A former State Department employee and his wife, accused of illegally aiding the government of Cuba for nearly 30 years, pleaded guilty Friday to federal charges.

Walter Kendall Myers, 72, pleaded guilty to a charge of conspiracy to commit espionage and two counts of wire fraud. He agreed to forfeit $1.7 million related to the two counts of wire fraud and to serve a life prison sentence.

His wife, Gwendolyn Steingraber Myers, 71, pleaded guilty to conspiracy to gather and transmit national defense information. She agreed to serve a sentence of between 6 and 7½ years in prison.

The couple, who appeared in U.S. District Court on Friday, were captured June 4 after an FBI agent posing as a Cuban intelligence officer managed to coax them into offering information on U.S. government personnel, authorities said.

In a diary quoted in the federal affidavit released in June, Myers expressed his opinions on the flaws of the United States and the appeal of Cuba. "The abuses of our system, the lack of decent medical system, the oil companies and their undisguised indifference to public needs, the complacency about the poor, the utter inability of those who are oppressed to recognize their own condition ...," he wrote of the United States.

"Have the Cubans given up their personal freedom to get material security? Nothing I have seen yet suggests that," he wrote. "I can see nothing of value that has been lost by the revolution. The revolution has released enormous potential and liberated the Cuban spirit."

The indictment said Kendall Myers, known to Cuban intelligence as Agent 202, and Gwendolyn Myers, known as Agent 123 and Agent E-634, engaged in activities "which spanned nearly three decades."

Conviction on the wire fraud charge would carry a sentence of up to 20 years, illegally acting as an agent of a foreign government would carry a sentence of up to 10 years, and the conspiracy charge would carry a sentence of up to five years.

A Justice Department official previously told CNN that counterespionage agents had gathered information on the couple and set up an April 15 meeting at which an FBI undercover agent convinced the couple he had been contacted by Cuban intelligence and was to ascertain the scope of their activities. They fell for the ruse, the department said.

According to court documents, the couple disclosed they had received coded messages via short-wave radio, had met with Cuban agents in Mexico and had been carefully watching for any sign of U.S. surveillance.

An affidavit released by the court said Kendall Myers first traveled to Cuba in 1978 and Cuban intelligence then began to develop him as a Cuban agent. Six months later, Myers and his wife agreed to work for the Cuban service, it said.

After the April 15 meeting, the Myerses allegedly agreed to provide the undercover agent with information on the April 17-19 Summit of the Americas in Trinidad and Tobago, which President Obama attended.

Kendall Myers confided to the undercover agent that he had received a "lot of medals" from the Cuban government for his work and that he and his wife met and spent an evening with Fidel Castro in 1995.

The affidavit quoted Kendall Myers as telling the undercover agent that he typically removed information from the State Department by memory or by taking notes, although he did occasionally take some documents home. He also said he had delivered information that was classified as secret.

Myers retired from the State Department on October 31, 2007. He had viewed more than 200 classified reports on Cuba in his final months, even though he was at the time an analyst working on European issues, the court document said.

CNN's Paul Courson contributed to this report.