The immune system is the body's specific defence. Every pathogen has antigens on its surface. When a pathogen enters the body, lymphocytes detect its antigens and make antibodies with a shape that fits those antigens exactly. Antibodies bind to the pathogen. They can make pathogens clump together and mark them so that phagocytes engulf them. Lymphocytes also make antitoxins, which neutralise toxins released by pathogens.
Making enough antibodies takes several days, which is why you can become ill during a first infection. Some lymphocytes become memory cells that stay in the blood. If the same pathogen enters again, the memory cells make the right antibodies quickly and in large numbers, so the pathogen is destroyed before you become ill. You are then immune to that disease. A different pathogen has different antigens, so the same antibody will not work against it.