Even longer. George Washington mandated smallpox inoculation for the army during the Revolutionary War in 1777, inoculating the current soldiers and then every recruit going forward.
At the time only about 1/4 of the soldiers had gained immunity by prior smallpox infection. The rest were vulnerable.
On the other side, most of the British soldiers had immunity so this put the Continental army at a big disadvantage, as a smallpox outbreak could incapacitate a whole regiment.
After the army was inoculated, they just suffered isolated smallpox infections that failed to incapacitate a single regiment.
The Native Americans and the slaves that had elected to fight for the British in exchange for their freedom did not have immunity and were devastated by smallpox, greatly reducing their impact on the war.