Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send an email without having to enable less secure apps in google

I made an e-mailer in C#, but you have to enable less secure apps in google. Is there a way around this? If not, how do other apps send e-mails securely without being classified as a less-secure app?

private void SendButton_Click(object sender, EventArgs e) {
       try {
           SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

           mail.From = new MailAddress(myUsername);
           mail.To.Add(RecipientEmailBox.Text);
           mail.Subject = SubjectField.Text;
           mail.Body = MessageField.Text;

           SmtpServer.Port = 587;
           SmtpServer.Credentials = new 
           System.Net.NetworkCredential(myUsername, Login.password);
           SmtpServer.EnableSsl = true;

           SmtpServer.Send(mail);
           MessageBox.Show("Message Sent!");

       } catch (Exception ex) {
           MessageBox.Show(ex.ToString());
       }
}

I tried researching ways to get around this, but I couldn't find anything.

like image 923
SpencerLS Avatar asked Oct 18 '25 02:10

SpencerLS


1 Answers

You can no longer configure your Google account to allow connections from less secure apps, since Google disabled that option starting May 30 2022. You have to generate an application password for your Google account.

First go to https://myaccount.google.com/security and enable 2 step verification. Once you've done that, go to 'app passwords' and generate an application password for the mail app to use on a windows computer. It will display you new app password on a yellow box, use it as your Login.password

like image 103
Saul Muñoz Garcia Avatar answered Oct 20 '25 17:10

Saul Muñoz Garcia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!