protected void btnRegistrar_Click(object sender, EventArgs e) { if (Request.Form["txtDocumento"] != "") { if (ctr_persona.CtrConsultarDocumentoPersona(int.Parse(Request.Form["txtDocumento"]))) { Session["documento"] = "Si existe"; //Documento_existe.Text = "Si existe"; //ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "mostrarMensaje", "DocumentoYaExiste();", true); } else { Session["documento"] = "No existe"; //Documento_existe.Text = "No existe"; } } if (Request.Form["txtCorreo"] != "") { if (ctr_persona.CtrconsultarPersonaPorCorreo(Request.Form["txtCorreo"])) { Session["correo_para_registro"] = "Si existe"; //ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "mostrarMensaje", "CorreoYaExiste();", true); } else { Session["correo_para_registro"] = "No existe"; //Correo_existe.Text = "No existe"; } } if (((int.Parse(Request.Form["verificado"]) == 1) && (string)Session["documento"] == "No existe") && (string)Session["correo_para_registro"] == "No existe") { //Registro a la persona que automáticamente se convierte en Cliente del sistema //string password = Helper.EncodePassword(string.Concat(Request.Form["txtCorreo"].Trim(), Request.Form["txtContra2"].Trim())); string password = Helper.EncodePassword(Request.Form["txtContra2"].Trim()); string token = Helper.EncodePassword(string.Concat(Request.Form["txtDocumento"].Trim(), Request.Form["txtCorreo"].Trim(), Request.Form["txtContra2"].Trim())); dto_cliente.dni = Request.Form["txtDocumento"].Trim(); dto_cliente.nombres = Request.Form["txtNombres"]; dto_cliente.apellidos = Request.Form["txtApellidos"]; dto_cliente.correo = Request.Form["txtCorreo"].Trim(); dto_cliente.clave = password; dto_cliente.img_ruta = "default-perfil.png"; dto_cliente.fecha_registro = System.DateTime.Now; dto_cliente.logo = "noimage.png"; dto_cliente.token = token; ctr_persona.Ctr_RegistrarPersona(dto_cliente); ctr_persona.Ctr_SeleccionarUltimaPersonaRegistrada(dto_persona); int id_persona_ultimo_registro = dto_persona.id_persona; dto_notificacion.fecha_emision = System.DateTime.Now; dto_notificacion.clase_visto = "novisto"; dto_notificacion.flg_visto = "0"; dto_notificacion.titulo_color = "text-success"; dto_notificacion.titulo = "Registro Exitoso"; dto_notificacion.mensaje = "Gracias : " + Request.Form["txtNombres"] + " " + Request.Form["txtApellidos"] + " por registrarte en MiHogar-Perú"; dto_notificacion.imagen = "mihogar-peru.png"; dto_notificacion.flg_noti_mostrado = "0"; dto_notificacion.id_persona = id_persona_ultimo_registro; ctr_notificacion.Ctr_InsertarNotificaciones(dto_notificacion); Session["documento"] = "destruido"; Session["correo_para_registro"] = "destruido"; EnviarCorreo(); ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "mostrarMensaje", "RegistroCompleto();", true); } }
public void Enviar_Notificacion_y_Correo() { DtoNotificacion dto_notificacion2 = new DtoNotificacion(); CtrNotificacion ctr_notificacion2 = new CtrNotificacion(); CtrPersona ctr_persona2 = new CtrPersona(); ctr_persona2.Ctr_SeleccionarUltimaPersonaRegistrada(dto_persona); int id_persona = dto_persona.id_persona; //Esta notificación es para la persona que fue registrada en el sistema por el admin dto_notificacion2.fecha_emision = System.DateTime.Now; dto_notificacion2.clase_visto = "novisto"; dto_notificacion2.flg_visto = "0"; dto_notificacion2.titulo_color = "text-success"; dto_notificacion2.titulo = "Registro Exitoso"; dto_notificacion2.mensaje = "Hola : " + Request.Form["txtNombres"] + " ya eres parte del personal en MiHogar-Perú"; dto_notificacion2.imagen = "mihogar-peru.png"; dto_notificacion2.flg_noti_mostrado = "0"; dto_notificacion2.id_persona = id_persona; ctr_notificacion2.Ctr_InsertarNotificaciones(dto_notificacion2); /*-------------------------MENSAJE DE CORREO----------------------*/ string nombres = Request.Form["txtNombres"]; string apellidos = Request.Form["txtApellidos"]; string correo = Request.Form["txtCorreo"]; string documento = Request.Form["txtDocumento"]; string contra_email = Session["clave_por_email"].ToString(); System.Net.Mail.MailMessage mmsg = new System.Net.Mail.MailMessage(); mmsg.To.Add(correo); mmsg.Subject = "Ya eres parte del personal en MiHogar-Perú"; mmsg.SubjectEncoding = System.Text.Encoding.UTF8; //Direccion de correo electronico que queremos que reciba una copia del mensaje //mmsg.Bcc.Add("*****@*****.**"); //Opcional mmsg.Body = "<div style='margin-top:20px; margin-bottom:20px; margin-right:auto; margin-left:auto; border-style:groove; position:relative; min-height:1px; padding-right:15px; " + "padding-left:15px; -webkit-box-flex:0; -webkit-flex: 0 0 50%; -ms-flex: 0 0 50%; flex: 0 0 50%; max-width:50%;'>" + "<div style='-webkit-box-flex:1; -webkit-flex:1 1 auto; -ms-flex:1 1 auto; flex:1 1 auto; padding:1.25rem'>" + "<div style='background-color:limegreen; margin-top:7px; margin-bottom:17px; padding-top:30px; padding-bottom:30px; align-items:center;'>" + "<h4 style='font-size:45px; margin-top:5px; margin-bottom:5px; color:#fff; text-align:center; font-weight:800;'> MiHogar-Perú </h4>" + "</div>" + "<p style ='margin-bottom:0;'> Hola " + nombres + " " + apellidos + " , ya formas parte del personal administrativo en MiHogar-Perú , tus datos registrados fueron:</p>" + "<div style='margin-top:10px; margin-bottom:10px; margin-right:auto; margin-left:auto; position:relative; width:100%; min-height:1px; padding-right:15px; padding-left:15px; -webkit-box-flex:0;" + "-webkit-flex:0 0 33.333333 %; -ms-flex:0 0 33.333333 %; flex:0 0 33.333333 %; max-width:33.333333 %; -webkit-box-flex: 0;'>" + "<p><span style='color:red;'> Correo : </span> " + correo + "</p>" + "<p><span style='color:red;'> Dni : </span> " + documento + "</p>" + "<p><span style='color:red;'> Clave : </span> " + contra_email + "</p>" + "</div>" + "<p style='margin-bottom:0'>" + "Tus demas datos de información los podras ver ingresando a la página en el panel de usuario y en ´´Mi Información" + "</p>" + "<div style='margin-top:20px; padding-top:10px; padding-bottom:10px; background-color: limegreen;' >" + "</div>" + "</div>" + "</div> "; mmsg.BodyEncoding = System.Text.Encoding.UTF8; mmsg.IsBodyHtml = true; //Si no queremos que se envíe como HTML mmsg.From = new System.Net.Mail.MailAddress("*****@*****.**"); /*-------------------------CLIENTE DE CORREO----------------------*/ System.Net.Mail.SmtpClient cliente = new System.Net.Mail.SmtpClient(); cliente.Credentials = new System.Net.NetworkCredential("*****@*****.**", "elcastito"); //Lo siguiente es obligatorio si enviamos el mensaje desde Gmail cliente.Port = 25; cliente.EnableSsl = true; cliente.Host = "smtp.gmail.com"; //Para Gmail "smtp.gmail.com"; /*-------------------------ENVIO DE CORREO----------------------*/ try { cliente.Send(mmsg); } catch (System.Net.Mail.SmtpException ex) { } }