public void setEmail(Modelo.Correo objCorreo) { try { MailMessage mail = new MailMessage(); mail.From = new MailAddress(objCorreo.from); mail.To.Add(objCorreo.to); mail.Subject = objCorreo.asunto; mail.Body = objCorreo.mensaje; if (objCorreo.tipo == 0) { mail.IsBodyHtml = false; } else if (objCorreo.tipo == 1) { mail.IsBodyHtml = true; } if (objCorreo.prioridad == 2) { mail.Priority = MailPriority.High; } else if (objCorreo.prioridad == 1) { mail.Priority = MailPriority.Low; } else if (objCorreo.prioridad == 0) { mail.Priority = MailPriority.Normal; } AlternateView htmlView = AlternateView.CreateAlternateViewFromString(objCorreo.mensaje, Encoding.UTF8, MediaTypeNames.Text.Html); LinkedResource img = new LinkedResource(objCorreo.imagen, MediaTypeNames.Image.Jpeg); img.ContentId = objCorreo.idImagen; htmlView.LinkedResources.Add(img); SmtpClient smtp = new SmtpClient(); smtp.Host = objCorreo.servidor; if (objCorreo.autenticacion) { smtp.Credentials = new System.Net.NetworkCredential(objCorreo.usuario, objCorreo.password); } if (objCorreo.puerto.Length > 0) { smtp.Port = Convert.ToInt32(objCorreo.puerto); } smtp.EnableSsl = objCorreo.conexionSegura; smtp.Send(mail); } catch (Exception) { throw; } }
public void setEmailLn(Modelo.Correo obCorreo) { try { LogicaNegocio.LnGeneral objGeneral = new LnGeneral(); objGeneral.setEmail(obCorreo); } catch (Exception ex) { throw ex; } }
protected void btnAceptar_Click(object sender, EventArgs e) { try { string stMensaje = string.Empty; if (string.IsNullOrEmpty(txtEmail.Text)) { stMensaje += "Ingresar email -"; } if (!string.IsNullOrEmpty(stMensaje)) { throw new Exception(stMensaje.TrimEnd(',')); } LogicaNegocio.LnUsuario objLnUsuario = new LogicaNegocio.LnUsuario(); Modelo.Usuario objUser = new Modelo.Usuario { correo_usuario = txtEmail.Text, rut_usuario = txtRut.Text }; List <Modelo.Usuario> lsConsulta = objLnUsuario.GetBuscarUsuarioCorreoRut(objUser); string nombre = null; string pass = null; string rut = null; string correo = null; if (lsConsulta.Count > 0) { foreach (var item in lsConsulta) { nombre = item.nombre_usuario; rut = item.rut_usuario; correo = item.correo_usuario; pass = item.password_usuario; } string[] stLogin = nombre.ToString().Split('@'); string stCuerpoHTML = "<!DOCTYPE html>"; stCuerpoHTML += "<html lang='es'>"; stCuerpoHTML += "<head>"; stCuerpoHTML += "<meta charset='utf - 8'>"; stCuerpoHTML += "<title>Recuperacion de correo</title>"; stCuerpoHTML += "</head>"; stCuerpoHTML += "<body style='background - color: black '>"; stCuerpoHTML += "<table style='max - width: 600px; padding: 10px; margin: 0 auto; border - collapse: collapse; '> "; stCuerpoHTML += "<tr>"; stCuerpoHTML += "<td style='padding: 0'>"; stCuerpoHTML += "<img style='padding: 0; display: block' src='cid:Fondo' width='100%' height='10%'>"; stCuerpoHTML += "</td>"; stCuerpoHTML += "</tr>"; stCuerpoHTML += "<tr>"; stCuerpoHTML += "<td style='background - color: #ecf0f1'>"; stCuerpoHTML += "<div style='color: #34495e; margin: 4% 10% 2%; text-align: justify;font-family: sans-serif'>"; stCuerpoHTML += "<h2 style='color: #e67e22; margin: 0 0 7px'>Hola " + stLogin[0] + "</h2>"; stCuerpoHTML += "<p style='margin: 2px; font - size: 15px'>"; stCuerpoHTML += "Hemos recibido una solicitud para restablecer el password de su cuenta asociada con "; stCuerpoHTML += "esta dirección de correo electrónico. Si no ha realizado esta solicitud, puede ignorar este "; stCuerpoHTML += "correo electrónico y le garantizamos que su cuenta es completamente segura."; stCuerpoHTML += "<br/>"; stCuerpoHTML += "<br/>";// nombredelvalor = valor & nombredelvalor2 = valor2 stCuerpoHTML += "Ingrese al siguiente link: " + "http://*****:*****@"\Imagenes\descuentos4.jpg", idImagen = "fondo", mensaje = stCuerpoHTML }; LogicaNegocio.LnRecuperarPassword lnRecuperar = new LogicaNegocio.LnRecuperarPassword(); lnRecuperar.setEmailLn(objCorreo); ClientScript.RegisterStartupScript(this.GetType(), "mensaje", "<script>swal('Correo enviado!'," + " 'Hemos enviado un email a su direccion de correo', 'success')</script>"); } else { throw new Exception("No se encontró información asociada a esa dirección de correo"); } } catch (Exception ex) { ClientScript.RegisterStartupScript(this.GetType(), "No se pudo enviar el email", "<script>swal('Error!'," + " '" + ex.Message + "!', 'error')</script>"); } }