Section 39H. A city, town, commission or district through its water department, if any, if thereunto authorized by ordinance, or by-law or by vote of its governing body if a commission or district or a water company, as defined in section one of chapter one hundred and sixty-five, may make contracts with, or may go to aid any other city, town, commission, district or any other water company, as so defined, with regard to the operation, administration, repair and maintenance of its water supply system. Any such ordinance, by-law or vote may authorize the head of the department in charge of sewers and drains to enter into contracts or to extend such aid subject to such conditions and restrictions as may be prescribed therein. Members of such departments of cities, towns, commissions or districts while in the performance of their duties under such contracts or in extending such aid shall have the same immunities and privileges as if performing the same work in their respective cities, towns, commissions, and districts. Any city, town, commission, district or water company aided under this section shall compensate any city, town, commission, district or water company rendering aid as aforesaid, for such aid and for the whole or any part of any damage to its property sustained in the course of rendering such aid. Any contracts under this section may be for a period not exceeding twenty years.