A general solution of the nonstationary problem of heat transfer between the rock body, the flowing drilling fluid, and the string of drill pipes is considered. Based on it, an exact solution of the respective stationary problem is presented. Unlike in the known methods, the heat flux in the axial direction of the well is taken into consideration. The solution is obtained with respect to the temperature of the drill pipes. As an example, thermal analysis of a 9000 m deep well is presented.