I have that $$\sum_{n=-\infty}^{\infty}\left(\left(\frac{1}{1+n^2}\right)e^{inx}\right)\text{.}$$ Where $f$ is the sumfunction for the serie. Then I have to find $\int_{-\pi}^{\pi}f\,sin(x)\mathrm{d}x$ and $\int_{-\pi}^{\pi}f\,cos(x)\mathrm{d}x$. I think I can find it without finding the sumfunction. Maybe swap the sum and integral? I think:
$$\sum_{n=-\infty}^{\infty}\left(\int_{-\pi}^{\pi}\left(\frac{e^{inx}}{1+n^2}cos(x)\right)dx\right)\text{}=\sum_{n=-\infty}^{\infty}\left(-\frac{2nsin(n\pi)}{n^4-1}\right)\text{}=\pi$$ Is that correct? And how can I formally show it? For $\int_{-\pi}^{\pi}f\,sin(x)\mathrm{d}x$ I got a expression with complex (with i). How can I deal with that sum?
The interchange of sum and integral is justified by uniform convergence. The series is uniformly convergent by M-test since $|e^{inx}|=1$ and $\sum \frac 1 {1+n^{2}} <\infty$. You have found $\int f(x) \cos x dx$ correctly but there are mistakes in what you have written. You cannot have $n^{4}-1$ in the denominator because $n=1$ is included in the sum. Try to re-write your calculation.
For $\int f(x) \sin x dx$ the answer is $i\pi$ and this is surely a complex number.
If $f$ was real valued you would get a real number for the integral but our function $f$ is complex valued so there is no contradiction.