Ошибка SMTP в Gmail при попытке запустить страницу регистрации на виртуальной основе c 2015 для проекта - PullRequest
0 голосов
/ 20 апреля 2020

Получение этой ошибки «SMTP-серверу требуется безопасное соединение, или клиент не был аутентифицирован. Ответ сервера: 5.7.0 Требуется аутентификация».

Вот мой код:

Partial Class SignUp
    Inherits System.Web.UI.Page
    Protected Sub registeruser(sender As Object, e As EventArgs) Handles btnSubmit.Click
        Dim userid As Integer = 0
        Using con As New SqlConnection("data source=(localdb)\mssqllocaldb;attachdbfilename=c:\users\is 4880\desktop\student_app\student_app\app_data\studentapp.mdf;integrated security=true")
            Using cmd As New SqlCommand("Insert_Users")
                Using sda As New SqlDataAdapter
                    cmd.CommandType = CommandType.StoredProcedure
                    cmd.Parameters.AddWithValue("@Username", txtUsername.Text.Trim())
                    cmd.Parameters.AddWithValue("@Password", txtPassword.Text.Trim())
                    cmd.Parameters.AddWithValue("@Email", txtEmail.Text.Trim)
                    cmd.Connection = con
                    con.Open()
                    UserId = Convert.ToInt32(cmd.ExecuteScalar())
                    con.Close()
                End Using
            End Using
            Dim messege As String = String.Empty
            Select Case userid
                Case -1
                    messege = "username already exists."
                Case -2
                    messege = "this email address has already been used before."
                Case Else
                    messege = "registration has been sucessful! please check your email to complete activation!"
                    sendactivationemail(userid)
                    Exit Select
            End Select
            ClientScript.RegisterStartupScript([GetType](), "alert",
           (Convert.ToString("alert( ' ") & messege) + " ');", True)
        End Using
    End Sub

    Private Sub sendactivationemail(UserId As Integer)
        Dim activationcode As String = Guid.NewGuid().ToString()
        Using con As New SqlConnection("data source=(localdb)\mssqllocaldb;attachdbfilename=c:\users\is 4880\desktop\student_app\student_app\app_data\studentapp.mdf;integrated security=true")
            Using cmd As New SqlCommand("insert into UserActivation values(@UserId,
    @ActivationCode)")
                Using sda As New SqlDataAdapter
                    cmd.CommandType = CommandType.Text
                    cmd.Parameters.AddWithValue("@UserId", UserId)
                    cmd.Parameters.AddWithValue("@ActivationCode", ActivationCode)
                    cmd.Connection = con
                    con.Open()
                    cmd.ExecuteNonQuery()
                    con.Close()
                End Using
            End Using
        End Using
        Using mm As New MailMessage("thisisthestudentapp@gmail.com", txtEmail.Text)


            mm.Subject = "student app account activation"
            Dim body As String = "hello " + txtUsername.Text.Trim() + ","
            body += "<br /><br />thank you for choosing the student app."
            body += "your attendance and rewards are on their way."
            body += "<br />please click the link below to activate your account."
            body += "<br />for security purposes the link will expire in 24 hours."
            body += "<br /><br />thank you and welcome!"
            body += "<br />-student app team"
            body += "<br /><br /><a href = '" +
           Request.Url.GetLeftPart(UriPartial.Authority) +
           Page.ResolveUrl("~/Activation.aspx?ActivationCode=" & ActivationCode) + "'> click here to
    activate your account!"
            mm.Body = body
            mm.IsBodyHtml = True
            Dim smtp As New SmtpClient()
            smtp.Host = "smtp.gmail.com"
            smtp.EnableSsl = True
            Dim networkcred As New System.Net.NetworkCredential()
            networkcred.UserName = "user@gmail.com"
            networkcred.Password = "****"
            smtp.UseDefaultCredentials = True
            smtp.Credentials = networkcred
            smtp.Port = 587
            smtp.Send(mm)
        End Using
    End Sub
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...