First let’s look at what is common between the two. Both of them use electro-magnetism to bring about a mechanical change in the system. Electric current passed through coil wound around a ferromagnetic material core, produces a magnetic field, strong enough to pull (usually, or sometimes push), another piece of ferro-magnetic object, from it’s state of equilibrium. The state of equilibrium is maintained by a relaxed (i.e. without stored mechanical energy) spring of some kind. When the electromagnetic coil is energised, the resulting magnetic field causes the equilibrium to be disturbed, a mechanial motion being created, and the sping to become tensed. This ensures that, once the electrical energy is removed, the system returns to it’s state of equilibrium, by coverting the stored mechanical energy in the spring to once again return back to it’s original state.
In both solenoid value and relay, this electrical energy, resulting in magnitism, resulting in mechanical motion, and removal of electrical energy, resulting in dissapearance of magnetism, resulting in (pulled/stressed spring led) mechanical motion performs the mechanical motions, that can perform push/pull, press/release, open/close, wind/unwind type of motions.
The above principle, now applied to solenoid value, results in a value (for liquid or gas) to open/shut, permitting or stopping it’s flow. Same principle applied to opening/closing another electrical circuit is what EM-relays do. In case of EM-relays, the controlling circuit that energizes the EM-relay’s coil, is physically isolated from the controlled circuit (which is opened/closed). The physical isolation is thanks to the air-gap, inside the EM-relay, and their only interaction is through the magnetism.