1897: A Trip to Venus, a novel by John Munro, available at Project Gutenberg. According to Technovelgy.com this seems to be the earliest mention of an "electric gun" (mass driver).
I'm not sure this counts; the concept of an electric gun for launching spacecraft is discussed in the book, but no such device is constructed in the story, and interplanetary travel is achieved by a different method, some sort of antigravity or space drive.
The following excerpt is part of a conversation between the narrator (I.) and Professor Gazen (G.), an astronomer, about possible methods for reaching the planets:
I. "We could even have an electric gun. Conceive a bobbin wound with insulated wire in lieu of thread, and having the usual hole through the axis of the frame. If a current of electricity be sent through the wire, the bobbin will become a hollow magnet or 'solenoid,' and a plug of soft iron placed at one end will be sucked into the hole. In this experiment we have the germ of a solenoid cannon. The bobbin stands for the gun-barrel, the plug for the bullet-car, and the magnetism for the ejecting force. We can arrange the wire and current so as to draw the plug or car right through the hole or barrel, and if we have a series of solenoids end to end in one straight line, we can switch the current through each in succession, and send the projectile with gathering velocity through the interior of them all. In practice the barrel would consist of a long straight tube, wide and strong enough to contain the bullet-car without flexure, and begirt with giant solenoids at intervals. Each of the solenoids would be excited by a powerful current, one after the other, so as to urge the projectile with accelerating speed along the tube, and launch it into the vast."
G. "That looks still better than the pneumatic gun."
I. "A magnetic gun would have several advantages. For instance, the currents can be sent through the solenoids in turn as quickly as we desire by means of a commutator in a convenient spot, for instance, at the butt end of the gun, so as to follow up the bullet with ease, and give it a planetary flight. By a proper adjustment of the solenoids and currents, this could be done so gradually as to prevent a starting shock to the occupants of the car. The velocity attained by the car would, of course, depend on the number and power of the solenoids. If, for example, each solenoid communicated to the car a velocity of nine yards per second, a thousand solenoids, each magnetically stronger than another in going from breech to muzzle, would be required to give a final velocity of five miles a second. In such a case, the length of the barrel would be at least 1,000 yards. Economy and safety would determine the best proportions for the gun, but we are now considering the feasibility of the project, not its cost. With regard to position and supports, the gun might be constructed along the slope of a hill or mound steep enough to give it the angle or elevation due to the aim. As the barrel would not have to resist an explosive force, it should not be difficult to make, and the inside could be lubricated to diminish the friction of the projectile in passing through it. Moreover, it is conceivable that the car need never touch the sides, for by a proper adjustment of the magnetism of the solenoids we might suspend it in mid-air like Mahomet's coffin, and make it glide along the magnetic axis of the tube."
G. "It seems a promising idea for an actual gun, or an electric despatch and parcel post, or even a railway. The bullet, I suppose, would be of iron."
I. "Probably; but aluminium is magnetic in a lower degree than iron, and its greater lightness might prove in its favour. We might also magnetise the car, say by surrounding it with a coil of wire excited from an accumulator on board. The car, of course, would be hermetically sealed, but it would have doors and windows which could be opened at pleasure. In open space it would be warmed and lighted by the sun, and in the shadow of a planet, if need were, by coal-gas and electricity. In either case, to temper the extremes of heat or cold, the interior could be lined with a non-conductor. Liquefied oxygen or air for breathing, and condensed fare would sustain the inmates; and on the whole they might enjoy a comfortable passage through the void, taking scientific observations, and talking over their experiences."
G. "It would be a novel observatory, quite free from atmospheric troubles. They might be able to make some astronomical discoveries."
I. "A novel laboratory as well, for in space beyond the attraction of the earth there would be no gravity. The travellers would not feel a sense of weight, but as the change would be gradual they would get accustomed to it, and suffer no inconvenience."