It's not so much what's in the water, as long as there are some mineral ions to conduct electrons. The corrosion is called galvanic corrosion, and occurs when a two metals come into contact with each other through an ionically conductive medium, typically water. The more active metal in the electrochemical series is corroded, and the less active is protected. If you have a stainless steel element in contact with a stainless kettle, no corrosion will occur. If as many of us do, you have a plain steel threaded section on your element, it will corrode instead of the stainless of the kettle. They can be protected by by putting a more active metal anode in the system. Typically magnesium or aluminum are used for anodes.
Your house water heater has a great big anode in it to protect the steel tank. The anode has to be in good electrical contact with the metal surface it is protecting, so they are bolted into place in keggles, and screw into place in water heaters.