Democratic presidential hopeful Hillary Clinton struggled with how to secure the endorsement of labor unions while announcing her opposition to the Keystone XL oil pipeline, a project they supported but environmentalists opposed, according to leaked emails published by Wikileaks on Oct. 7.

Before announcing in September 2015 that she opposed TransCanada Corp.'s (NYSE: TRP) proposal to build a pipeline from Canada to the U.S., her campaign sought to "soften the blow" to labor unions by offering an energy infrastructure plan that would create jobs, according to the emails.

The internal campaign emails from August 2015 reveal the difficulty Clinton had in appeasing both unions and environmentalists as she fought for her party's nomination ahead of the Nov. 8 election.

Wikileaks published the Clinton emails just hours after the U.S. government accused Russia of a campaign of cyber attacks against Democratic Party organizations.

In the emails, Clinton advisers discussed how to frame the candidate's "energy infrastructure" plan, which would call for replacing old pipelines, repairing rail tracks and improving the electric grid in a way that would appeal to labor unions, who had yet to endorse her at that stage.

"Could we mention that ... as we transition HRC wants to create more careers within the new energy economy? Careers is their buzz word," wrote Nikki Budzinski, labor outreach director for Hillary for America.

Clinton had long avoided taking a firm position on Keystone, which had been pending for seven years, as she sought her party's nomination last year. As secretary of state, Clinton said in 2010 she was inclined to approve it.

Rival Senator Bernie Sanders had been a staunch opponent of the pipeline. President Barack Obama did not reject the pipeline until November 2015.

Labor unions have pushed for approval of the pipeline, saying it would create thousands of construction jobs while environmentalists opposed it because it would increase greenhouse gas emissions from Canada's oil sands.

The emails show that North America's Building Trades, representing builders and construction workers, contacted the campaign after hearing that Obama would announce his denial of the pipeline in late August and that Clinton would say she "encouraged" him to make the decision.

"We are so close to getting bldg (sic) trades and if we do this right, it will be ok even though they won't like it," wrote Amanda Renteria, the campaign's national political adviser.

The Building Trades union endorsed Clinton in November and the Laborers' International Union of North America endorsed Clinton in December.

Clinton's struggle to please both green and labor groups is likely to emerge as a key challenge if she is to win the presidency.

A decision over another pipeline, the Dakota Access, has sparked major protests from Native American and environmental groups.

The Obama administration temporarily halted construction, frustrating unions.

"These types of decisions made by this administration get dumped in the presidential race and it's kind of unfair," Sean McGarvey, president of North America's Building Trades Unions, told Reuters in an interview last month.

"We don't like all of Clinton's energy policies but we think it's reasonable," McGarvey said.

RELATED:

Bakken Pipeline Under Siege After Obama Sidesteps His Own Judge

Obama Rejects Keystone XL, Raises Industry Hackles

Study: Toll Of Clinton’s Fracking Ban Would Be ‘Severe’