When you use SharePoint Framework to develop and build custom WebParts code, you can (and should) use the context provided in the parent WebPart component
this.context and send it via its properties to your root WebPart component (the rendered ones).
Now your component has the context and capabilities to use the provided SPHttpClient, which does the authentication and work for you:
this.props.context.spHttpClient. with the methods
If you are not using SharePoint Framework now, you are on a SharePoint page where you can no longer retrieve a request digest (and need one to transfer data). You must first ask for one and use it in a
X-RequestDigest Headers in your mail requests.
The Office365 app page does not contain a RequestDigest
The method is to create a first POST
Hope that helps!