  We generalize the Cottingham formula at finite (T\neq 0) temperature by using
the imaginary time formalism. The Cottingham formula gives the theoretical
framework to compute the electromagnetic mass differences of the hadrons using
a dispersion relation approach. It can be also used in other contexts, such as
non leptonic weak decays, and its generalization to finite temperature might be
useful in evaluating thermal effects in these processes. As an application we
compute the \pi^+-\pi^0 mass difference at T\neq 0; at small T we reproduce the
behaviour found by other authors: \delta m^2(T)= \delta
m^2(0)+\mathcal{O}(\alpha T^2), while for moderate T, near the deconfinement
temperature, we observe deviations from this behaviour.
