4

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.

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
SpencerLS
  • 361
  • 5
  • 16

2 Answers2

2

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

1

I think this is answer for question.

You can use the Google OAuth API with C#. For how to do, read the guide.

OnePage
  • 116
  • 1
  • 13