With GMail, you don't use your normal account and password. You need to generate a "special" app paasword for the email address that you want to use. Please read this:
Sign in with app passwords - Gmail Help[
^]
Here is a quick'n'dirty (tested & working) .Net 7.0 console app to test with:
using System.Diagnostics;
using System.Net.Mail;
using System.Net;
var smtpClient = new SmtpClient("smtp.gmail.com")
{
Port = 587,
Credentials = new NetworkCredential(
"[gmail email address]",
"[generated app password]"),
EnableSsl = true,
};
try
{
smtpClient.Send(
from: "[gmail email address]",
recipients: "[one or more recipient email addresses]",
subject: "Test message",
body: "This is a test message sent from .Net 7.0 application");
}
catch (SmtpException ex)
{
Debugger.Break();
}