Section 17A. No gas or electric company shall, except in accordance with such rules and regulations as the department shall from time to time prescribe, loan its funds to, guarantee or endorse the indebtedness of, or invest its funds in the stock, bonds, certificates of participation or other securities of, any corporation, association or trust unless the said loan, guaranty or endorsement, or investment is approved in writing by the department. A director, treasurer or other officer or agent of a gas or electric company who makes such loan, guaranty or endorsement or purchases such securities or votes to authorize such loan, guaranty or endorsement or such purchase in violation of this section shall be punished by a fine of not more than one thousand dollars or by imprisonment for not more than one year, or both. Any company supplying electricity in bulk which is authorized by special act to engage in manufacture or to construct mills or factory buildings, or to otherwise construct or develop real estate for industrial purposes, shall be exempt from the provisions of this section.