An exact solution for dipole fields inside optical multilayer structures