As of the end of May, 2022, Google no longer allows enabling "Less secure apps". So, I'm not able to use Basic authentication (i.e. user name and password) for sending e-mails using SMTP.
The MailKit FAQ is suggesting to use OAuth2, but when I implement the suggested code to my REST service, a browser opens at the web server (currently localhost
as I'm still developing my REST service), displaying "Access blocked: This app's request is invalid":
My REST service is supposed to run unattented. I won't be able to (a) enter any credentials, not (b) react to such visual error messages.
How can I safely sent e-mails with my REST service using a GMail account?