public void Enviar(MailMessage mensaje) { try { server.Send(mensaje); } catch (Exception ex) { Utiles.Log(ex); } }
public ServidorCorreo() { server.Credentials = new System.Net.NetworkCredential(Utiles.NOMBRE_SERVIDOR_CORREO(), Utiles.CLAVE_SERVIDOR_CORREO()); if (Utiles.ENABLE_SSL() == "1") { server.EnableSsl = true; } else { server.EnableSsl = false; } //server.DeliveryMethod = SmtpDeliveryMethod.Network; //server.UseDefaultCredentials = false; }
public static System.Net.Mail.MailMessage ConstruyeMensajeContacto(string nombre, string telefono, string email, string motivo) { System.Net.Mail.MailMessage sms = new System.Net.Mail.MailMessage(); sms.Subject = "Formulario Contacto CPAS"; sms.To.Add(Utiles.NOMBRE_SERVIDOR_CORREO()); string habilitaCopiaAdmin1 = Utiles.HABILITA_COPIA_ADMIN1(); if (habilitaCopiaAdmin1 == "1") { sms.To.Add(COPIA_ADMIN_1()); } string habilitaCopiaAdmin2 = Utiles.HABILITA_COPIA_ADMIN1(); if (habilitaCopiaAdmin2 == "1") { sms.To.Add(COPIA_ADMIN_2()); } sms.From = new System.Net.Mail.MailAddress("*****@*****.**", "CPAS"); sms.IsBodyHtml = true; StringBuilder sb = new StringBuilder(); sb.Append("<html>"); string htmlMensaje = ObtenerMensajeXML("Contacto", true); if (htmlMensaje != null) { htmlMensaje = htmlMensaje.Replace("{Nombre}", nombre).Replace("{Telefono}", telefono).Replace("{Email}", email).Replace("{Motivo}", motivo); sb.Append(htmlMensaje); } else { sb.AppendFormat("{0}, Teléfono Contacto {1}, correo electónico {2}:<br />", nombre, telefono, email); sb.AppendFormat("Desea contactarse mediante el formulario de contacto, donde ha ingresado el siguiente motivo: {0}<br />", motivo); sb.Append("***** Mensaje enviado desde el sistema automático de envio de correos de CPAS ******"); } sb.Append("</html>"); sms.Body = sb.ToString(); return(sms); }
public static List <UsuariosCorreos> ListaUsuariosCorreosPorInstId(int instId) { List <UsuariosCorreos> retorno = new List <UsuariosCorreos>(); try { List <Entidad.AutentificacionUsuario> listaUsuarios = NegocioMySQL.AutentificacionUsuario.ListarUsuariosPorInstId(instId); if (listaUsuarios != null && listaUsuarios.Count > 0) { foreach (Entidad.AutentificacionUsuario au in listaUsuarios) { if (au.CorreoElectronico != "") { if (!retorno.Exists(p => p.Correo == au.CorreoElectronico)) { UsuariosCorreos us = new UsuariosCorreos(); us.Correo = au.CorreoElectronico; //us.Nombre = au.Persona.Nombres + " " + au.Persona.ApellidoPaterno + " " + au.Persona.ApellidoMaterno; Entidad.Persona persona = NegocioMySQL.Persona.ObtenerPersonaPorUsuId(au.Id); if (persona != null && persona.Id > 0) { us.Nombre = persona.Nombres + " " + persona.ApellidoPaterno + " " + persona.ApellidoMaterno; } else { us.Nombre = au.NombreUsuario; } retorno.Add(us); } } } } } catch (Exception ex) { Utiles.Log(ex); } return(retorno); }
public static string ObtenerCalendarioInstJson(int instId) { string json = ""; List <VCFramework.Entidad.Calendario> lista = ObtenerCalendarioPorInstId(instId); List <events> events = new List <events>(); if (lista != null && lista.Count > 0) { foreach (VCFramework.Entidad.Calendario cal in lista) { events.Add(new events { title = cal.Titulo, start = Utiles.ConstruyeFecha(cal.FechaInicio), end = Utiles.ConstruyeFecha(cal.FechaTermino), url = cal.Url }); } } json = JsonConvert.SerializeObject(events); return(json); }
public static void CrearEvento(int Id, string Descripcion, DateTime FechaInicio, DateTime FechaTermino, int Status, string Asunto, string Ubicacion, int Etiqueta, int Tipo, int InstId, bool Borrado) { if (Tipo == 0) { Factory fac = new Factory(); Entidad.Calendario calendario = new Entidad.Calendario(); calendario.Asunto = Asunto; try { if (Descripcion == null) { Descripcion = "Sin Descripción"; } calendario.Descripcion = Descripcion; calendario.Etiqueta = Etiqueta; calendario.FechaInicio = FechaInicio; calendario.FechaTermino = FechaTermino; //ver como sacar la institucion calendario.InstId = InstId; calendario.Status = Status; calendario.Tipo = Tipo; if (Ubicacion == null) { Ubicacion = ""; } calendario.Ubicacion = Ubicacion; calendario.Url = ""; calendario.Detalle = Descripcion; calendario.Titulo = Descripcion; fac.Insertar <Entidad.Calendario>(calendario, setCnsWebLun); if (NegocioMySQL.Utiles.ENVIA_CORREO_EVENTO(InstId) == "1") { List <UsuariosCorreos> correos = UsuariosCorreos.ListaUsuariosCorreosPorInstId(InstId); List <string> listaCorreos = new List <string>(); if (correos != null && correos.Count > 0) { foreach (UsuariosCorreos us in correos) { listaCorreos.Add(us.Correo); } } if (listaCorreos != null && listaCorreos.Count > 0) { NegocioMySQL.ServidorCorreo cr = new NegocioMySQL.ServidorCorreo(); Entidad.Institucion institucion = NegocioMySQL.Institucion.ObtenerInstitucionPorId(InstId); string fecha1 = Utiles.ConstruyeFecha(FechaInicio); string fecha2 = Utiles.ConstruyeFecha(FechaTermino); MailMessage mnsj = NegocioMySQL.Utiles.ConstruyeMensajeCrearEvento(institucion.Nombre, Asunto, fecha1 + " " + fecha2, Ubicacion, listaCorreos, true); cr.Enviar(mnsj); } } } catch (Exception ex) { throw new Exception(ex.Message); } } else { throw new Exception("No puede crear un Evento del Tipo Proyecto."); } }
public static System.Net.Mail.MailMessage ConstruyeMensajeCrearEvento(string nombreInstitucion, string nombreEvento, string fechaInicioYTermino, string ubicacion, List <string> correos, bool esNuevo) { System.Net.Mail.MailMessage sms = new System.Net.Mail.MailMessage(); sms.Subject = "Evento en CPAS"; string habilitaCopiaAdmin1 = Utiles.HABILITA_COPIA_ADMIN1(); if (habilitaCopiaAdmin1 == "1") { sms.To.Add(COPIA_ADMIN_1()); } string habilitaCopiaAdmin2 = Utiles.HABILITA_COPIA_ADMIN1(); if (habilitaCopiaAdmin2 == "1") { sms.To.Add(COPIA_ADMIN_2()); } //recorremos la lista de usuarios de la institución if (correos != null && correos.Count > 0) { foreach (string s in correos) { sms.To.Add(s); } } sms.From = new System.Net.Mail.MailAddress("*****@*****.**", "CPAS"); sms.IsBodyHtml = true; StringBuilder sb = new StringBuilder(); sb.Append("<html>"); if (esNuevo) { string htmlMensaje = ObtenerMensajeXML("Evento", true); if (htmlMensaje != null) { htmlMensaje = htmlMensaje.Replace("{NombreItem}", nombreEvento).Replace("{NombreInstitucion}", nombreInstitucion).Replace("{FechaInicioTermino}", fechaInicioYTermino).Replace("{Url}", ObtenerUrl()); sb.Append(htmlMensaje); } else { sb.AppendFormat("Se ha agregado el evento <strong>{0}</strong>, para el Establecimiento {1}:<br />", nombreEvento, nombreInstitucion); sb.AppendFormat("Estimado Usuario CPAS, ha sido agregado un evento para su establecimiento, este tendrá lugar en {0} entre {1}, ingrese a www.cpas.cl para poder verlo.", ubicacion, fechaInicioYTermino); sb.Append("<br />"); sb.Append("***** Mensaje enviado desde el sistema automático de envio de correos de CPAS ****** <br />"); sb.Append("</html>"); } } else { string htmlMensaje = ObtenerMensajeXML("Evento", false); if (htmlMensaje != null) { htmlMensaje = htmlMensaje.Replace("{NombreItem}", nombreEvento).Replace("{NombreInstitucion}", nombreInstitucion).Replace("{FechaInicioTermino}", fechaInicioYTermino).Replace("{Url}", ObtenerUrl()); sb.Append(htmlMensaje); } else { sb.AppendFormat("Ha sido modificado el evento <strong>{0}</strong>, para el Establecimiento {1}:<br />", nombreEvento, nombreInstitucion); sb.AppendFormat("Estimado Usuario CPAS, ha sido agregado un evento para su establecimiento, este tendrá lugar en {0} entre {1}, ingrese a www.cpas.cl para poder verlo.", ubicacion, fechaInicioYTermino); sb.Append("<br />"); sb.Append("***** Mensaje enviado desde el sistema automático de envio de correos de CPAS ****** <br />"); sb.Append("</html>"); } } sms.Body = sb.ToString(); return(sms); }