I want to calculate $S = \sum_{k=1}^{k=\infty} \frac{\cos(k x)}{k^2}$ using the method of residues.
By using the function $f(z) = z \sum_{k=1}^{k=\infty} \frac{1}{k(z-k)}$, which has simple poles at $k = 1, 2, 3, ...$ with residue 1, and $h(z) = \frac{cos(z x)}{z^2}$ I write the sum as
$ S = e \lim_{\epsilon \rightarrow 0} \oint f(z) h(z) e^{-e^{\epsilon |z|}} = \lim_{\epsilon \rightarrow 0} \sum_{k=1}^{k=\infty} Res(f(z) h(z) e^{-e^{\epsilon |z|}})|_{z=k} = S$
With the contour going around all the positive integers. Now, I added the function $e^{-e^{\epsilon |z|}}$ to ensure convergence, so that I can deform the contour to a circle with radius infinity, to give me 0.
Because the only other residue I pick up comes from the pole of $h(z)$ at $z = 0$, $S$ is given by
$ S = -e \lim_{\epsilon \rightarrow 0} Res( f(z) h(z) e^{-e^{\epsilon |z|}})|_{z=0} = -\frac{\pi^2}{6}$
But this is not what I expect, since $S = \frac{1}{12}(3x^2 - 6 \pi x + 2 \pi^2)$, see here.
Can someone point out my faulty reasoning?