title: GMail API / OAUTH2 - How To Send Emails With Traditional C# SMTP Method Being Deprecated?
body: <p>As per notice from Google's <a href="https://support.google.com/accounts/answer/6010255" rel="nofollow noreferrer">Less Secure App Deprecation Notice</a>, on May 30, 2022 the ability access Google accounts through 'less secure apps' is being deprecated. The C# code below is how I have been sending emails from my own personal GMail account. I only send emails from my app. I do not do anything else (read emails, create drafts, etc...) from this account, only sending. Basically, it is the equivalent of sending &quot;no-reply&quot; emails.</p>
  <pre><code>// C# code
  using (SmtpClient smtpClient = new SmtpClient(SmtpDomain, SmtpPortNumber))
  {
      smtpClient.DeliveryMethod = SmtpDeliveryMethod;
      smtpClient.UseDefaultCredentials = UseDefaultCredentials;
      smtpClient.EnableSsl = true;
      smtpClient.Credentials = new NetworkCredential(SmtpUsername, SmtpPassword);
  
      MailMessage mailMessage = new MailMessage { /* ... */ };
      
      smtpClient.Send(mailMessage);
  }
  </code></pre>
  <p>I've started looking at Google's API and OAuth documentation but I feel like I am going down a dark rabbit hole here since I am not wanting to access other users data, just only send emails from my own account. I assume from research that OAuth2 is the preferred way to do things when at all possible but I can't find a clear cut of example of &quot;if you are doing it this way now&quot;, &quot;then start doing this way&quot;. Can someone point me to the absolute starting point of the path I need to take to update my code so that I can continue sending emails from my own personal account/app?</p>