Example #1
0
    public void enviaCorreoSeguimiento(SeguimientoBE s)
    {
        String usuariosmtp = "", clavesmtp = "", hostsmtp = "", emailorigen = "";
        int puertosmtp = 25;
        Correo correo = new Correo();
        SmtpClient smtp = new SmtpClient();
        MailMessage Mensaje = new MailMessage();
        Attachment Anexo;

        try
        {
            usuariosmtp = ConfigurationManager.AppSettings["usuariosmtp"];
            clavesmtp = ConfigurationManager.AppSettings["clavesmtp"];
            puertosmtp = Convert.ToInt32(ConfigurationManager.AppSettings["puertosmtpssl"]); ;
            hostsmtp = ConfigurationManager.AppSettings["hostsmtp"];
            emailorigen = ConfigurationManager.AppSettings["emailorigen"];

            if (usuariosmtp != "" && clavesmtp != "")
            {
                smtp.Credentials = new NetworkCredential(usuariosmtp, clavesmtp);
                smtp.EnableSsl = true;
            }

            smtp.Port = puertosmtp;
            smtp.Host = hostsmtp;
            Mensaje.Subject = "Nuevo Seguimiento";
            Mensaje.Body = "Se ha ingresado un nuevo seguimiento a una consultora";
            Mensaje.From = new MailAddress(emailorigen);
            Mensaje.To.Clear();

            DataTable dtCorreo = new DataTable();
            dtCorreo = correo.obtener("", "", 37, s.PaisID);
            String cuenta = "";

            foreach (DataRow fila in dtCorreo.Rows)
            {
                cuenta = fila["email"].Equals(DBNull.Value) ? "" : fila["email"].ToString();
                if (cuenta != "")
                {
                    Mensaje.To.Add(cuenta);
                }
            }

            String gzregion = s.ZonaCodigo.Substring(0, 2);
            String gzzona = s.ZonaCodigo.Substring(2, 4);

            GerenteZona gz = new GerenteZona();
            DataTable dtgz = gz.obtener("", gzregion, gzzona);
            foreach (DataRow drgz in dtgz.Rows)
            {
                Mensaje.To.Add(drgz["email"].ToString());
            }
            Anexo = new Attachment(rutaAnexoSeguimiento(s.ConsultoraCodigo));
            Mensaje.Attachments.Add(Anexo);

            smtp.Send(Mensaje);
        }
        catch (Exception ex)
        {
            Log.lanzarError(ex);
        }
        finally
        {

        }

        correo = null;
        smtp = null;
        Mensaje = null;
    }
Example #2
0
    protected void cmdGuardar_Click(object sender, EventArgs e)
    {
        String reingresoID;
        String consultoraID;
        String usuariosmtp = "", clavesmtp = "", hostsmtp = "", emailorigen = "";
        int i, n;
        int puertosmtp = 25;
        Correo correo = new Correo();
        SmtpClient smtp = new SmtpClient();
        MailMessage Mensaje = new MailMessage();
        Attachment Anexo;

        usuariosmtp = ConfigurationManager.AppSettings["usuariosmtp"];
        clavesmtp = ConfigurationManager.AppSettings["clavesmtp"];
        puertosmtp = Convert.ToInt32(ConfigurationManager.AppSettings["puertosmtpssl"]); ;
        hostsmtp = ConfigurationManager.AppSettings["hostsmtp"];
        emailorigen = ConfigurationManager.AppSettings["emailorigen"];

        if (usuariosmtp != "" && clavesmtp != "")
        {
            smtp.Credentials = new NetworkCredential(usuariosmtp, clavesmtp);
            smtp.EnableSsl = true;
        }
        smtp.Port = puertosmtp;
        smtp.Host = hostsmtp;

        Mensaje.Subject = "Nueva IncorporaciĆ³n";
        Mensaje.Body = "Se ha verificado la incorporacion de nuevas consultoras";
        Mensaje.From = new MailAddress(emailorigen);
        Mensaje.To.Clear();

        DataTable dtCorreo = new DataTable();
        dtCorreo = correo.obtener("", "", 36, Convert.ToInt32(Session["paisID"]));
        String cuenta = "";

        foreach (DataRow fila in dtCorreo.Rows)
        {
            cuenta = fila["email"].Equals(DBNull.Value) ? "" : fila["email"].ToString();
            if (cuenta != "")
            {
                Mensaje.To.Add(cuenta);
            }
        }

        n = gvReingreso.Rows.Count;
        for (i = 0; i < n; i++)
        {
            if (((CheckBox)gvReingreso.Rows[i].Cells[11].Controls[1]).Checked != ((CheckBox)gvReingreso.Rows[i].Cells[12].Controls[1]).Checked)
            {
                reingresoBL.registraVerificacion(int.Parse(gvReingreso.Rows[i].Cells[0].Text));
                try
                {
                    GerenteZona gz = new GerenteZona();
                    String gzregion = gvReingreso.Rows[i].Cells[1].Text;
                    String gzzona = gvReingreso.Rows[i].Cells[2].Text;
                    DataTable dtgz = gz.obtener("", gzregion, gzzona);
                    foreach (DataRow drgz in dtgz.Rows)
                    {
                        Mensaje.To.Add(drgz["email"].ToString());
                    }
                    reingresoID = gvReingreso.Rows[i].Cells[0].Text;
                    consultoraID = gvReingreso.Rows[i].Cells[1].Text;
                    Anexo = new Attachment(rutaAnexo(reingresoID, consultoraID));
                    Mensaje.Attachments.Add(Anexo);

                    smtp.Send(Mensaje);
                }
                catch (Exception ex)
                {
                    Log.lanzarError(ex);
                }
            }
        }
        cmdBuscar_Click(sender, e);
        divMensaje.InnerHtml = "<div id=\"success\">Grabado con exito.</div>";
    }