Seth Aaron Ator was banned from having a firearm because he was diagnosed with a mental illness.

The gunman who killed seven people and wounded 23 others in a rampage across West Texas on Saturday obtained the assault-style rifle used through a private sale after he was banned from having a firearm because he was diagnosed with a mental illness, media reported.

The gunman, identified as Seth Aaron Ator, 36, carried out the shooting spree in the neighbouring cities of Midland and Odessa, shortly after he was fired from his trucking job. He called local emergency 911 responders and then an FBI tip line to make rambling statements, but did not threaten to commit violence, officials said.

After the calls, Ator opened fire on civilians and police officers in a roving series of shootings, at one point hijacking a U.S. Postal Service truck before dying in an exchange of gunfire with law enforcement, police said.

Ator bought the assault-style rifle through a private sale after being prohibited by federal law from possessing a firearm because he had been diagnosed with a mental illness by a clinician, ABC news reported, citing federal and local law enforcement.

Private firearm sellers are not required to run background checks on potential buyers, but they are not allowed to sell a weapon to a person who has been flagged by law enforcement under federal law.

Democrats in Congress want to close such loopholes that allow certain people to sell firearms without requiring background checks, such as in sales conducted online, at gun shows or out of their homes.

Ator had been rejected when he tried to buy a gun and his name was run through the National Instant Criminal Background Check System, said John Wester, assistant special agent in charge of the Dallas office of the U.S. Bureau of Alcohol, Tobacco, Firearms and Explosives.

President Donald Trump called the Odessa-Midland shooter "a very sick person," but said increased background checks on gun buyers would not have prevented many mass shootings in the United States in the past few years.

Trump said last month he had spoken to the National Rifle Association gun rights group about closing loopholes in background checks, but he did not want to take away the constitutional right to own guns.

The rampage followed the Aug. 3 shooting in El Paso, Texas, by a man from the Dallas area, in a massacre that killed 22 people. El Paso is about 255 miles (410 km) west of Midland.