We apply the Gauss-Bonnet theorem to the study of light rays in a plasma medium in a static and spherically symmetric gravitational field and also to the study of timelike geodesics followed for test massive particles in a spacetime with the same symmetries. The possibility to using the theorem follows from a correspondence between timelike curves followed by light rays in a plasma medium and spatial geodesics in an associated Riemannian optical metric. A similar correspondence follows for massive particles. For some examples and applications, we compute the deflection angle in weak gravitational fields for different plasma density profiles and gravitational fields.PACS numbers: