A North Carolina inmate’s elaborate plan to blow up a jail for his grand escape was thwarted after he mailed details of the plot to the wrong person, cops said.

Sean Damion Castorina, 43, had planned to escape Alamance County Detention Center before he mixed up mailing addresses that sent his letter with details of his scheme to a woman in Graham, FOX8 reported. Castorina, who is being held on a first-degree murder charge and was the mastermind of the plan, allegedly conspired with Shannon Douglas Gurkin, 23, and Dakota Lee Markek, 24, in the scheme.

The woman said she received the letter from the prison on Dec. 6 that contained a detailed drawing of the facility and instructions for making a bomb. The letter stated the bomb would have been planted on the south side of the detention center where it would detonate, creating a hole to help Castorina and others escape.

The woman reported the letter to authorities, who later found more evidence in Castorina’s cell and recorded phone conversations that he was planning the bombing and escape.

Officials said the letter helped thwart a plot that would have injured inmates, government officials and jail staff.

ESCAPED CHILD KILLER MISSING FOR MORE THAN 40 YEARS MAY BE ‘HIDING IN PLAIN SIGHT,’ FEDS SAY

Castorina faces additional charges of attempting to escape a county jail, manufacturing and assembling a weapon of mass destruction and felony conspiracy.

Gurkin and Markek were charged with malicious use of an explosive to damage property.

Castorina was arrested in the kidnapping and murder of Harold Simpson, whose remains were discovered in August 2017. Castorina attempted to escape from the jail’s annex unit earlier this year.

He is being held in solitary confinement until his trial, the Times-News of Burlington reported.