Google sign-in blocked my email sending feature!

chairmanPC

Active member
Joined
Apr 19, 2021
Messages
29
Programming Experience
10+
I created an email sending form for my company project.

Here is my code below:

My email sending program:
private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage message = new MailMessage();
                SmtpClient smtp = new SmtpClient();
                message.From = new MailAddress(textBoxUserEmail.Text);
                message.To.Add(new MailAddress(textBoxCustomerEmail.Text));
                message.Subject = "Test";
                message.IsBodyHtml = true;
                message.Body = textBoxMessage.Text;
                smtp.Port = 587;
                smtp.Host = "smtp.gmail.com";
                smtp.EnableSsl = true;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = new NetworkCredential(textBoxUserEmail.Text, textBoxPassword.Text);
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

                smtp.Send(message);
                this.Close();
            }catch (Exception sendingEx)
            {
                ErrorForm error = new ErrorForm();
                error.label3.Text = sendingEx.Message;
                error.ShowDialog();
                this.Close();
            }
        }

This is my form:
For the attachments feature, I'll get to that soon.


I tested it by sending a simple message to myself, and then I got this "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required." message, followed by gmail sending me an email of a blocked sign-in attempt.

How can I fix this? Is there a way to make Google trust my app or something?
 
Last edited:
Top Bottom