"I love the fact that you will give your life for my daughter and myself. You guys are absolute heroes and I mean that from the bottom of my heart,'' Greene wrote in the note from his Gmail account.

The funeral procession for Urbandale police officer Justin Martin makes its way to the Rosehill Cemetery on Tuesday, Nov. 8, 2016, in Rockwell City, Iowa. Law enforcement officers and much of the small Iowa community of Rockwell City are mourning the death of 24-year-old police officer who died nearly a week after he and another officer were gunned down in their patrol cars in the Des Moines area. (Source: AP Photo)

Days before he allegedly killed two Iowa police officers, Scott Michael Greene sent a note to one of their departments apologizing for prior run-ins, saying his “dark days” were over and praising police as “absolute heroes.” In an online compliment form addressed to the “many officers” of the Urbandale Police Department, the unemployed 46-year-old father wrote Oct. 29: “I love you folks.”

Watch what else is making news

“I love the fact that you will give your life for my daughter and myself. You guys are absolute heroes and I mean that from the bottom of my heart,” Greene wrote in the note from his Gmail account. “I’m so proud to have you guys around. I respect each and every one of you with all my heart. I really do.”

Four days after the laudatory email, authorities say Greene shot and killed first-year Urbandale police officer Justin Martin, 24, and Des Moines Police Sgt. Anthony Beminio, 38. The ambush-style attacks took place about two miles apart within minutes of each other as both officers were sitting in their patrol cars. Greene is in jail awaiting trial on two counts of first-degree murder, which would put him in prison for life if convicted.

The Associated Press exclusively obtained the document and dozens of others about Greene on Thursday from the Urbandale Community School District under the open records law. The district had initially refused to release them at the urging of Urbandale police, arguing they were part of a police report and confidential. The district reversed course after the AP argued that exemption did not apply to school records.

The records reveal that for two weeks before the shootings, Greene was enraged by the district’s decision to bar him for security reasons from district activities. The district acted after Greene had waved a large Confederate flag in front of black spectators at a high school football game Oct. 14. He told the district he targeted those spectators with the flag because he was upset they did not stand for the national anthem.

Greene warned school officials in a rambling email Oct. 26 that he wasn’t violent but that “you messed with the wrong guy.” He said the ban was a violation of his civil rights and promised legal action to restore the right to watch his daughter perform on the high school cheerleading team and in other extracurricular activities.

“I will fight you guys like a pit bull who’s been fed gunpowder,” he wrote to the principal and superintendent. After the flag incident, police escorted Greene out of the game and temporarily banned him from school property. He later posted video of the incident on YouTube. One of the black parents who was targeted told the principal in an email that he expected additional security measures to prevent future harassment, saying many fans were on edge given the racial unrest going on nationwide.

“The last thing I want is for anything ‘newsworthy’ to occur and take focus away from the sporting event,” the parent wrote Oct. 17.

District officials asked Greene not to attend the following week’s game at a neighboring school district, but he showed up anyway. At that game, district activities director William Watson wrote in an email that Greene asked the school to lift the ban, citing “his desire when he was on his deathbed to state that he had been to all of his kids’ events.” High school principal Brian Coppess told Watson that he believed Greene was “really enjoying all the attention” and remained a threat.

“I think something we need to be prepared for is that if Scott does end up missing an event, we have increased security at that event in preparation for whatever he might try,” Coppess wrote Oct. 24. He said additional administrators should also be on hand “because there’s no way of knowing what he might try next.” Later that day, Urbandale superintendent Steve Bass sent Greene a letter notifying him he had banned him under school board policy from attending district events for 90 school days — through March 9, 2017.

Noting that one parent complained that the flag incident was “racial hatred,” Bass told Greene his actions were demeaning to spectators and interfered with the event. He warned Greene would be removed or prosecuted for trespassing if he didn’t comply with the ban. While Greene opposed the ban in calls, emails and meetings with school officials, he struck a different tone in his Oct. 29 compliment to Urbandale police. He said that he was sorry for causing disruption but that he was trying to exercise his free speech rights in the flag incident.

“I was sticking up for you men and women in blue,” he wrote. “I could not stand anymore to see people sit during the anthem … They are not protesting anything except for their hatred towards police.” He said that he suffered from post-traumatic stress disorder but that he has gotten it “worked out lately so you’re not gonna hear much of me anymore.”

“I respect each and every one of you with all my heart,” he wrote. “I apologize that I ran my mouth and shown such disrespect at times but my dark days are over. I’ve been treated. I’ve been healed.”