Send mail with ASP .NET in visual studio 2017

1

hello good afternoon my problem is the following codie to send emails from my visual studio 2017, but the problem that once I do run the program and charge all fields, I click the send button is waiting for a time (I have to understand that it takes a while to send an email) and then it closes only the debugging (stops running the program). Any ideas? I have to configure something in my visual

  protected void btnEnviar_Click(object sender, EventArgs e)
    {
        SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
        smtp.Credentials = new NetworkCredential(txtRemitente.Text, txtContraseña.Text);
        MailMessage msj = new MailMessage();
        msj.From = new MailAddress(txtRemitente.Text);
        msj.To.Add(new MailAddress(txtDestinatario.Text));
        msj.Subject = txtAsunto.Text;
        msj.Body = txtMensaje.Text;
        try
        {
            smtp.Send(msj);
            lblMensaje.Text = "Fue enviado con exito";
        }
        catch (Exception ex)
        {

            lblMensaje.Text = ex.ToString();
        }

    }

frontend

Remitente: <asp:TextBox ID="txtRemitente" runat="server"></asp:TextBox>

<br />
<br />

Contraseña: <asp:TextBox ID="txtContraseña" runat="server" TextMode="Password" ></asp:TextBox>

<br />
<br />

Asunto: <asp:TextBox ID="txtAsunto" runat="server"></asp:TextBox>

<br />
<br />

Destinatario: <asp:TextBox ID="txtDestinatario" runat="server"></asp:TextBox>

<br />
<br />

Mensaje: <asp:TextBox ID="txtMensaje" runat="server"></asp:TextBox>

<br />
<br />
<asp:Label ID="lblMensaje" runat="server" Text=""></asp:Label>

<asp:Button ID="btnEnviar" runat="server" Text="Enviar" OnClick="btnEnviar_Click" />
    
asked by Dieguito Weed 20.11.2018 в 19:31
source

0 answers