How can I send e-mails from my ASP.NET Core web service using public free e-mail providers?

AxD 671 Reputation points
2023-08-15T21:39:08.3233333+00:00

I created a web service that's supposed to dispatch e-mails using a public free e-mail provider, e.g. GMail or Outlook.com

A few years ago, this would have been a snap using SMTP and STARTTLS. Yet, as of the end of May, 2022, Google and Microsoft no longer allow 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.

I have been searching for documentation on how to do things now, but I'm not able to succeed.

So, I asked the MailKit team, followed their suggestions at https://github.com/jstedfast/MailKit/issues/1620, but to no avail: https://stackoverflow.com/questions/76871274/how-can-i-send-e-mails-from-my-gmail-account-using-rest-service

Now I'm lost: How do I send e-mails from an unattended ASP.NET Core web service, installed in a Docker container, using a public free e-mail provider? What's an up-to-date, bullet-proof approach and solution?

Your answers are very much appreciated.

Developer technologies ASP.NET ASP.NET Core
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2023-08-16T15:19:54.51+00:00

    Most modern email systems use oauth authentication. The default flow requires a browser, for application access you typically a client secret to get the access token. The mail service will have admin support to create the secret. For gmail

    https://support.google.com/cloud/answer/6158849?hl=en#:~:text=Go%20to%20the%20Google%20Cloud%20Platform%20Console%20Credentials%20page.,to%20add%20a%20new%20secret.

    then use mailkit oauth support.

    1 person found this answer helpful.
    0 comments No comments

  2. AxD 671 Reputation points
    2023-09-18T12:25:52.8066667+00:00

    Thanks for trying to help!

    I tried all the documentation provided so far, but to no avail. All I get is error messages and a browser window displayed for logging in. Documentation isn't helpful at all.

    So, I give up now. This is too much rocket science for me. I will use a simple SMTP provider with basic authentication for my purposes.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.