Solution (source code)

= Solution

The integrand has simple poles at $z=ia$ and $z=-ia$. Only the first is inside the upper contour, and its <residue> is
$$
\operatorname{Res}_{z=ia}\frac{e^{iz}}{z^2+a^2}=\frac{e^{-a}}{2ia}.
$$
The <residue theorem> therefore gives, for every $R>a$,
$$
\boxed{\oint_C\frac{e^{iz}}{z^2+a^2}dz=\frac\pi a e^{-a}.}
$$
On the upper semicircle, $|e^{iz}|=e^{-\operatorname{Im}z}\leq1$ and $|z^2+a^2|\geq R^2-a^2$. The <estimation lemma> bounds the arc contribution by $\pi R/(R^2-a^2)\to0$. Hence the real-axis integral has the same limit, and taking its real part gives
$$
\boxed{\int_{-\infty}^{\infty}\frac{\cos x}{a^2+x^2}dx=\frac\pi a e^{-a}.}
$$
The imaginary part vanishes independently because $\sin x/(a^2+x^2)$ is odd. The real integral converges absolutely, since the denominator grows quadratically.