Two pin PWM signal to control solenoid/electromagnet
Looks like the power on the fan connector on the Melzi board is controlled with a RFP30N06LE power transistor...

https://reprap.org/mediawiki/images/7/7d/Melzi-circuit.png
This is a very beefy transistor that can switch up to 30 amps...

https://www.mouser.com/ProductDetail/ON-Semiconductor-Fairchild/RFP30N06LE?qs=mdiO5HdF0KgGbixxeJqneA%3D%3D
...so your solenoid should be no problem.
You will want to add a flyback diode across the solenoid so that it does not generate a high voltage across the transistor when the power is turned off. You can google about how that works.

Pick (or make) a solenoid that is rated for 12V so that it does not get too hot and burn out. You can use a lower voltage solenoid too, just do not leave it on long enough for it to get hot.