How is Spam Like An Infection?

When visiting certain websites, you can accidentally download a script or program that will cause your computer to start sending out emails. These scripts or programs are the infection, that must be removed by programs that can remove them, while the spam is the result of the infection.