Example #1
0
        protected void PreparandoEnvioCorreo(CorreoEntidad correo, string asunto, string cuerpo)
        {
            try
            {
                var correoEntidad = correo;

                MailMessage mail = new MailMessage();

                SmtpClient smtp = new SmtpClient(correoEntidad.Servidor);
                smtp.Port        = correoEntidad.Puerto;
                smtp.EnableSsl   = correoEntidad.Ssl ?? false;
                smtp.Credentials = new NetworkCredential(correoEntidad.De, correoEntidad.Password);

                mail.From = new MailAddress(correoEntidad.De);
                mail.To.Add(correoEntidad.Para);
                mail.Subject = asunto;

                ContentType contentType = new ContentType("text/html");

                AlternateView alternateView = AlternateView.CreateAlternateViewFromString(cuerpo, contentType);

                mail.AlternateViews.Add(alternateView);


                smtp.Send(mail);

                smtp.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Example #2
0
        public override void Enviar()
        {
            var gmail = new CorreoEntidad();

            gmail.Password = _password;
            gmail.De       = _de;
            gmail.Para     = _para;
            gmail.Puerto   = 587;
            gmail.Ssl      = true;
            gmail.Servidor = "smtp.gmail.com";

            this.PreparandoEnvioCorreo(gmail, _asunto, _cuerpo);
        }