How to prove $\int_{0}^{\infty} \frac{\sin x}{x(x^2+1)}dx=\frac{\pi}{2}(1-\frac{1}{e})$ by residue calculus? How to prove $$I=\int_{0}^{\infty} \frac{\sin x}{x(x^2+1)}dx=\frac{\pi}{2}(1-\frac{1}{e})\, ?$$
Let $$f(z)=\frac{\sin z}{z(z^2+1)}=\frac{e^{iz}-e^{-iz}}{2i\,z(z^2+1)}.$$
Then I have no idea how to deal with $[0,\infty)$.
Can anyone please give me a hint?  Thanks in advance.
 A: First note that the integrand is an even function so that
$$\int_0^\infty \frac{\sin(x)}{x(x^2+1)}\,dx=\frac12 \int_{-\infty }^\infty \frac{\sin(x)}{x(x^2+1)}\,dx\tag1$$
Next, we can use Euler's Formula $e^{ix}=\cos(x)+i\sin(x)$ in $(1)$ to write
$$\frac12 \int_{-\infty }^\infty \frac{\sin(x)}{x(x^2+1)}\,dx=\frac12 \text{Im}\left(\int_{-\infty }^\infty \frac{e^{ix}}{x(x^2+1)}\,dx\right)\tag2$$
where the integral on the right-hand side of $(2)$ is interpreted as a Cauchy Principal Value.
Then, we analyze the contour integral $I$ where
$$I=\oint_C \frac12  \frac{e^{iz}}{z(z^2+1)}\,dz$$
where the closed contour $C$ is comprised of $(i)$ the straight line segments from $-R$ to $-\varepsilon$ and from $\varepsilon$ to $R$ (where $R>1$ and $R>\varepsilon>0$), $(ii)$ the circular arc in the upper-half plane, centered at the origin, with radius $\varepsilon$ from $-\varepsilon$ to $\varepsilon$, and $(iii)$ the circular arc in the upper-half plane, centered at the origin, with radius $R$ from $R$ to $-R$.
The value of this integral is equal to $2\pi i $ times the residue of the integrand at $z=i$.
As $R\to \infty $ show that the contribution to the value of $I$ from integration over the semicircular arc of radius $R$ approaches $0$.
As $\varepsilon\to 0^+$, show that contribution to the value of $I$ from integration over the semicircular arc of radius $\varepsilon$ approaches $i\pi$ times the residue of the integrand at $z=0$.
Finally, put everything together to arrive at the coveted result.
Can you proceed now?
A: You can notice since your $f$ is even it is
$$\int_0^{\infty} f(x) \text{d}x=\frac{1}{2} \int_{-\infty}^{\infty} f(x) \text{d}x$$
A: It helps to use $\tfrac{1}{x(x^2+1)}=\tfrac1x-\tfrac{x}{x^2+1}$ to reduce the problem to $I=\tfrac12\pi-J$ with$$J:=\int_0^\infty\tfrac{x\sin xdx}{x^2+1}=\tfrac12\Im\int_{\Bbb R}\tfrac{x\exp ixdx}{x^2+1}=\tfrac12\Im[2\pi i\lim_{x\to i}\tfrac{x\exp ix}{x+i}]=\tfrac{\pi}{2e}.$$
