The following information has been culled from Mental Floss Presents: Condensed Knowledge, some web articles and a variety of encyclopedic sources.
Historically, smallpox has been a blight on humanity. Prior to 1725, it killed more than 100 million people. It was eventually eradicated (well, almost) thanks to a worldwide vaccination campaign. Today the virus lives only in laboratories and (possibly) in the hands of a few madmen.
How did we get so lucky? You can thank Edward Jenner, who experimented with using material from cowpox pustules. He injected this material into human subjects (horrors!) to see if this would grant them immunity to smallpox. Sure enough, it worked! (Incidentally, the name "vaccine" is derived from the Latin "vacca," which means "cow.")
It turns out that the human immune system can remember being exposed to an antigenic invader. In some cases, this allows the immune system to mount a better defense against subsequent exposures. Cowpox virus is very similar to smallpox virus, so a person who had a harmless case of cowpox is granted immunity to the much more harmful smallpox virus.
Today, the vaccinia strain is used to inoculate people against smallpox. Its origin is not entirely understood, but one theory is that this is a hybrid between the cowpox and smallpox viruses. Vaccines against other diseases are developed using other mimic viruses (such as cowpox for smallpox), attenuated (or heat-killed) viruses, and even just fragments of viral proteins.