The correct DC voltage across a solenoid or relay is important to ensure it actuates and doesn't overheat. A resistor in series with a low voltage solenoid may be useful to allow it to be operated from a higher voltage. For example the KEMET EC2-5NU is a 5V relay with a coil resistance of 178 ohms. To run it off 12V a series resistor of about 250 ohms would be suitable. This will be inefficient as both will have a 28mA current flowing through them.
As it is likely that a relay is being switched by a micro controller a better (more efficient) way is to pulse width modulate the driving transistor, in this case with a duty cycle of 5/12 or 42%. The average current will then be less, about 12mA.
As DC motors draw different current as their back EMF changes the PWM approach is the only suitable approach to use.