A Gray man was sentenced to 17 1/2 years in federal prison Tuesday for conspiring to distribute bath salts, fentanyl and heroin, U.S. Attorney Thomas E. Delahanty II said.

Scot Stolkner, 44, of Gray was sentenced in U.S. District Court in Portland by Judge Jon Levy. Stolkner pleaded guilty on April 1 to trafficking bath salts, heroin and fentanyl throughout Maine. Stolkner obtained heroin and fentanyl from New Hampshire and Massachusetts suppliers and bath salts through the mail from sources outside the United States, a statement from the U.S. Attorney’s Office said.

Stolkner sold the drugs himself and through other dealers, the statement said.

The U.S. Drug Enforcement Administration and the Scarborough and Portland police departments investigated the case.