Send Email to smtp.gmail.com from C# after 5/30/2022

Bill Bell 6 Reputation points
2022-05-02T13:56:12.777+00:00

I have a C# program which sends mail using smtp.gmail.com as SMTP server.  It uses  System.Net.Mail.  I use my email address and password and turn on "Allow less secure apps" option in my GMAIL account. Everything works well.  On May 30, 2022 Google will disable "Allow less secure apps".  Has anyone addressed this issue.

On my Gmail Account.
Some apps and devices use less secure sign-in technology, which makes your account vulnerable. You can turn off access for these apps, which we recommend, or turn it on if you want to use them despite the risks. Google will automatically turn this setting OFF if it’s not being used. Learn moreAllow less secure apps: ONOn May 30, 2022, this setting will no longer be available. Learn more

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,223 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 55,366 Reputation points
    2022-05-02T16:47:27.723+00:00

    you need to convert to oauth authentication:

    https://developers.google.com/gmail/imap/xoauth2-protocol

    you may want to use a clientid

    https://developers.google.com/identity/gsi/web/guides/get-google-api-clientid

    if it is a program with a UI you may want to host a web view for login to get the token. you can also use httpclient post the form and host web server port for the authentication server to redirect back to. (register localhost:<port> as a valid reply url).

    if the application does not have a UI, you will want a separate program with a UI that saves the refresh token somewhere the app can access. The token will expire and need to be updated periodically.

    1 person found this answer helpful.
    0 comments No comments

  2. Castorix31 81,636 Reputation points
    2022-05-03T07:05:00.35+00:00
    1 person found this answer helpful.
    0 comments No comments