This paper. discusses recent theoretical efforts to develop a general and flexible method for the calculation of the field distributions around and inside complex optical systems involving both dielectric and metallic materials. Starting from the usual light-matter coupling Hamiltonian, we derive a self-consistent equation for the optical field in arbitrary optical systems composed of N different subdomains. We show that an appropriate solving procedure based on the real-space discretization of each subdomain raises the present approach to the rank of an accurate predictive numerical scheme. In order to illustrate its applicability, we use this formalism to address challenging problems related to nonradiative energy transfers in near-field optics. in particular, we investigate in detail the detuning of a microresonator probed by a near-field optical probe.