Hello everyone. There is such a code for sending messages from the Gmail box

SqlCommand _command = new SqlCommand(@"INSERT INTO BaseAccaunt(Login, Password, Email, Phone, Birthday, Status) VALUES(@Login, @Password, @Email, @Phone, @Birthday, @Status)", _connection); _command.Parameters.AddWithValue("Login", TextBox1.Text); _command.Parameters.AddWithValue("Password", TextBox2.Text); _command.Parameters.AddWithValue("Email", TextBox4.Text); _command.Parameters.AddWithValue("Phone", TextBox5.Text); _command.Parameters.AddWithValue("Birthday", TextBox6.Text); _command.Parameters.AddWithValue("Status", 0); _command.ExecuteNonQuery(); string server = ConfigurationManager.AppSettings["server"]; string port = ConfigurationManager.AppSettings["port"]; string login = ConfigurationManager.AppSettings["login"]; string password = ConfigurationManager.AppSettings["password"]; MailMessage message = new MailMessage(); message.Subject = "Подтверждение регистрации"; message.From = new MailAddress(login); message.To.Add(new MailAddress(TextBox4.Text)); MD5CryptoServiceProvider md5Provider = new MD5CryptoServiceProvider(); byte[] hashCode = md5Provider.ComputeHash(Encoding.Default.GetBytes(TextBox1.Text + TextBox2.Text)); string url = "http://localhost:6333/Check.aspx?code=" + BitConverter.ToString(hashCode).ToLower().Replace("-", ""); message.Body = "перейдите по ссылке <A HREF="+url+">"; message.IsBodyHtml = true; message.BodyEncoding = Encoding.UTF8; SmtpClient client = new SmtpClient(); client.Host = server; client.Port = Convert.ToInt32(port); client.EnableSsl = true; client.Credentials = new NetworkCredential(login, password); try { client.Send(message); } catch(Exception excep) { Label1.Text += " " + excep.Message; Label1.Visible = true; } 

config

 <appSettings> <add key="server" value="smtp.gmail.com"/> <add key="port" value="587"/> <add key="login" value="test86spade@gmail.com"/> <add key="password" value="5618131Sd"/> 

Throws exception when sending - Server response: 5.5.1 Authentication Required.

As I understood from similar topics, you must first enable two-step authentication. After that, get the password for the application and use it to send emails.

I understand that the two-step process should be done via SMS? (Should you not receive SMS when using the password?) And how to use the application code in my code?

    0