First-principles study of magnetization relaxation enhancement and spin transfer in thin magnetic films