Exemplo n.º 1
0
        public void eliminarUsuarioAspNet(string userId)
        {
            CrediAdminContext storeContext = new CrediAdminContext();
            var item = storeContext.aspnetusers.Find(userId);

            if (item != null)
            {
                storeContext.aspnetusers.Remove(item);
                storeContext.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public static bool enviarFromAWS(int empresaRemitente, string email, string asunto, string mensaje)
        {
            CrediAdminContext db          = new CrediAdminContext();
            paramcorreo       paramcorreo = (paramcorreo)db.paramcorreo.FirstOrDefault(em => em.EmpresaId == empresaRemitente);

            if (paramcorreo != null)
            {
                empresa      empresa      = (empresa)db.empresa.Find(empresaRemitente);
                EnviarCorreo enviarcorreo = new EnviarCorreo()
                {
                    Empresa      = empresa.Nombre,
                    Servidor     = paramcorreo.Servidor,
                    Puerto       = paramcorreo.Puerto,
                    Usuario      = paramcorreo.Usuario,
                    Password     = paramcorreo.Password,
                    Destinatario = email,
                    Asunto       = asunto, //Nombre.ToUpper()+" Bienvenido a CrediAdmin",
                    Mensaje      = mensaje,
                    //"<p>Ya puede ingresar a nuestra plataforma para administrar sus creditos.</p> <p>Nombre de Usuario:" + EmpEmail + "</p><p>Contraseña:" + clave + "</p>",
                    Adjunto = ""
                };

                var    fromAddress  = new MailAddress(enviarcorreo.Usuario, enviarcorreo.Empresa);
                var    toAddress    = new MailAddress(enviarcorreo.Destinatario, "");
                string fromPassword = enviarcorreo.Password;
                string subject      = enviarcorreo.Asunto;
                string body         = enviarcorreo.Mensaje;

                String FROM = enviarcorreo.Usuario; // "*****@*****.**";   // Replace with your "From" address. This address must be verified.
                String TO   = email;                //"*****@*****.**";  // Replace with a "To" address. If your account is still in the
                // sandbox, this address must be verified.

                String SUBJECT = asunto;  //"Amazon SES test (SMTP interface accessed using C#)";
                String BODY    = mensaje; //"This email was sent through the Amazon SES SMTP interface by using C#.";

                // Supply your SMTP credentials below. Note that your SMTP credentials are different from your AWS credentials.
                String SMTP_USERNAME = ConfigurationManager.AppSettings["AWSAccessKey"].ToString();
                //  "AKIAIZOJPFIFCACIJ53A";  // Replace with your SMTP username.
                String SMTP_PASSWORD = ConfigurationManager.AppSettings["AWSSecretKey"].ToString();
                //   "Au9jMcd8Z07RmDNYgEvxs9f+3rpf46RruJ+1LgGEbzr5";  // Replace with your SMTP password.

                // Amazon SES SMTP host name. This example uses the US West (Oregon) region.
                String HOST = ConfigurationManager.AppSettings["AWSServer"].ToString();

                // Port we will connect to on the Amazon SES SMTP endpoint. We are choosing port 587 because we will use
                // STARTTLS to encrypt the connection.
                const int PORT = 587;

                MailMessage message = new MailMessage(fromAddress, toAddress);
                message.Subject    = subject;
                message.Body       = body;
                message.IsBodyHtml = true;
                System.Net.Mail.Attachment attachment = null;
                if (!String.IsNullOrEmpty(enviarcorreo.Adjunto))
                {
                    attachment = new System.Net.Mail.Attachment(enviarcorreo.Adjunto);
                }

                // Create an SMTP client with the specified host name and port.
                using (System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(HOST, PORT))
                {
                    // Create a network credential with your SMTP user name and password.
                    client.Credentials = new System.Net.NetworkCredential(SMTP_USERNAME, SMTP_PASSWORD);

                    // Use SSL when accessing Amazon SES. The SMTP session will begin on an unencrypted connection, and then
                    // the client will issue a STARTTLS command to upgrade to an encrypted connection using SSL.
                    client.EnableSsl = true;

                    // Send the email.
                    try
                    {
                        //  Console.WriteLine("Attempting to send an email through the Amazon SES SMTP interface...");
                        //client.Send(FROM, TO, SUBJECT, BODY);
                        client.Send(message);
                        //Console.WriteLine("Email sent!");
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("The email was not sent.");
                        Console.WriteLine("Error message: " + ex.Message);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 3
0
        public static bool enviarCorreo(int empresaRemitente, string email, string asunto, string mensaje)
        {
            CrediAdminContext db          = new CrediAdminContext();
            paramcorreo       paramcorreo = (paramcorreo)db.paramcorreo.FirstOrDefault(em => em.EmpresaId == empresaRemitente);

            if (paramcorreo != null)
            {
                empresa      empresa      = (empresa)db.empresa.Find(empresaRemitente);
                EnviarCorreo enviarcorreo = new EnviarCorreo()
                {
                    Empresa      = empresa.Nombre,
                    Servidor     = paramcorreo.Servidor,
                    Puerto       = paramcorreo.Puerto,
                    Usuario      = paramcorreo.Usuario,
                    Password     = paramcorreo.Password,
                    Destinatario = email,
                    Asunto       = asunto, //Nombre.ToUpper()+" Bienvenido a CrediAdmin",
                    Mensaje      = mensaje,
                    //"<p>Ya puede ingresar a nuestra plataforma para administrar sus creditos.</p> <p>Nombre de Usuario:" + EmpEmail + "</p><p>Contraseña:" + clave + "</p>",
                    Adjunto = ""
                };

                var    fromAddress  = new MailAddress(enviarcorreo.Usuario, enviarcorreo.Empresa);
                var    toAddress    = new MailAddress(enviarcorreo.Destinatario, "");
                string fromPassword = enviarcorreo.Password;
                string subject      = enviarcorreo.Asunto;
                string body         = enviarcorreo.Mensaje;

                System.Net.Mail.Attachment attachment = null;
                if (!String.IsNullOrEmpty(enviarcorreo.Adjunto))
                {
                    attachment = new System.Net.Mail.Attachment(enviarcorreo.Adjunto);
                }

                var smtp = new SmtpClient
                {
                    Host           = enviarcorreo.Servidor,
                    Port           = enviarcorreo.Puerto,
                    EnableSsl      = true,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    // UseDefaultCredentials = true,
                    UseDefaultCredentials = false,
                    Credentials           = new System.Net.NetworkCredential(fromAddress.Address, fromPassword)
                };
                MailMessage message = new MailMessage(fromAddress, toAddress);
                message.Subject    = subject;
                message.Body       = body;
                message.IsBodyHtml = true;
                if (attachment != null)
                {
                    message.Attachments.Add(attachment);
                }
                try
                {
                    smtp.Send(message);
                    //Response.Redirect(urlPapa, true);
                    return(true);
                }
                catch (Exception ex)
                {
                    //ViewBag.mensaje = "Exception caught in CreateTestMessage2(): {0}" + ex.ToString();
                    Console.WriteLine("Exception caught in CreateTestMessage2(): {0}", ex.ToString());
                }
            }
            return(false);
        }