コード例 #1
0
        public static void processaEmail()
        {
            if (DateTime.Now.DayOfWeek == DayOfWeek.Monday && DateTime.Now.Hour >= 17)
            {
                //  if(false)
                if (!WasSent(2))
                {
                    var A03_UKEYS = new List <string>
                    {
                        "F7CDA95A-A8E9-4C2B-B"
                    };


                    foreach (var A03_UKEY in A03_UKEYS)
                    {
                        var OcorrenciasConfirmadas = new List <OcorrenciaConhecimento>(); //Ocorrencias com entrega
                        var OcorrenciasEmAberto    = new List <OcorrenciaConhecimento>(); //Ocorrencias que não foram entregas

                        var FileNamePendente = string.Empty;

                        OcorrenciasEmAberto    = GenerateCSV2(0, A03_UKEY, "PENDENTE_");
                        FileNamePendente       = attachmentFilename;
                        OcorrenciasConfirmadas = GenerateCSV2(1, A03_UKEY, "ENVIO_7_DIAS_");


                        if ((OcorrenciasEmAberto != null && OcorrenciasEmAberto.Count() != 0) || (OcorrenciasConfirmadas != null && OcorrenciasConfirmadas.Count() != 0))
                        {
                            try
                            {
                                var EmailToSend = string.Empty;

                                if (OcorrenciasConfirmadas != null && OcorrenciasConfirmadas.Count() != 0)
                                {
                                    EmailToSend = RetornaConhecimento.GetEmailByConhecimentoUkey(OcorrenciasConfirmadas.FirstOrDefault().UkeyConhecimento);
                                }
                                else if (OcorrenciasEmAberto != null && OcorrenciasEmAberto.Count() != 0)
                                {
                                    EmailToSend = RetornaConhecimento.GetEmailByConhecimentoUkey(OcorrenciasEmAberto.FirstOrDefault().UkeyConhecimento);
                                }
                                else
                                {
                                    throw new Exception("Nenhuma ocorrencia encontrada para buscar email de enivo! Entre em contato com o desenvolvedor!");
                                }


                                var body = @"
                                            <strong>Atenção:</strong>
                                            Este é um envio de e-mail automático via sistema e não deve ser respondido.
                                            Qualquer dúvida, entre em contato diretamente com a Daytona Express 
                                            ";

                                using (var smtpClient = new SmtpClient("mail.daytonaexpress.com.br"))
                                {
                                    smtpClient.UseDefaultCredentials = false;
                                    smtpClient.Host        = "mail.daytonaexpress.com.br";
                                    smtpClient.Port        = 587;
                                    smtpClient.EnableSsl   = false;
                                    smtpClient.Credentials = new NetworkCredential("*****@*****.**", "dayt@011");



                                    var emailMensage = new MailMessage
                                    {
                                        IsBodyHtml = true,
                                        From       = new MailAddress("*****@*****.**"),
                                        Body       = body,
                                        Subject    = "Informativo de Ocorrência",
                                    };
                                    //emailMensage.To.Add(new MailAddress(Email.EmailToSend));
                                    //emailMensage.To.Add(new MailAddress(EmailToSend));
                                    //emailMensage.To.Add(new MailAddress("*****@*****.**"));
                                    //emailMensage.To.Add(new MailAddress("*****@*****.**"));
                                    emailMensage.To.Add(new MailAddress("*****@*****.**"));
                                    emailMensage.To.Add(new MailAddress("*****@*****.**"));
                                    emailMensage.To.Add(new MailAddress("*****@*****.**"));


                                    try
                                    {
                                        if (OcorrenciasConfirmadas != null && OcorrenciasConfirmadas.Count() != 0)
                                        {
                                            Attachment         attachment  = new Attachment(attachmentFilename, MediaTypeNames.Application.Octet);
                                            ContentDisposition disposition = attachment.ContentDisposition;
                                            disposition.CreationDate     = File.GetCreationTime(attachmentFilename);
                                            disposition.ModificationDate = File.GetLastWriteTime(attachmentFilename);
                                            disposition.ReadDate         = File.GetLastAccessTime(attachmentFilename);
                                            disposition.FileName         = Path.GetFileName(attachmentFilename);
                                            disposition.Size             = new FileInfo(attachmentFilename).Length;
                                            disposition.DispositionType  = DispositionTypeNames.Attachment;
                                            emailMensage.Attachments.Add(attachment);
                                        }
                                        if (OcorrenciasEmAberto != null && OcorrenciasEmAberto.Count() != 0)
                                        {
                                            Attachment         attachmentPendente = new Attachment(FileNamePendente, MediaTypeNames.Application.Octet);
                                            ContentDisposition disposition        = attachmentPendente.ContentDisposition;
                                            disposition.CreationDate     = File.GetCreationTime(FileNamePendente);
                                            disposition.ModificationDate = File.GetLastWriteTime(FileNamePendente);
                                            disposition.ReadDate         = File.GetLastAccessTime(FileNamePendente);
                                            disposition.FileName         = Path.GetFileName(FileNamePendente);
                                            disposition.Size             = new FileInfo(FileNamePendente).Length;
                                            disposition.DispositionType  = DispositionTypeNames.Attachment;
                                            emailMensage.Attachments.Add(attachmentPendente);
                                        }


                                        smtpClient.Send(emailMensage);
                                    }catch (Exception e)
                                    {
                                    }
                                }


                                if (OcorrenciasConfirmadas != null && OcorrenciasConfirmadas.Count() != 0)
                                {
                                    foreach (var OcorrenciaConhecimento in OcorrenciasConfirmadas.Where(x => x.LogRegister == 1).ToList())
                                    {
                                        var _cmd = "INSERT INTO  OCORRENCIAS_ENVIADAS_ENTRADA_ENTREGA  VALUES(@SEQ,'@UKEYCONHECIMENTO',@CODIGO,@STATUS,CONVERT(DATETIME,'@DATA',120),'@MENSAGEM',@typeRel)";

                                        _cmd = _cmd.Replace("@SEQ", OcorrenciaConhecimento.Seq.ToString());
                                        _cmd = _cmd.Replace("@UKEYCONHECIMENTO", OcorrenciaConhecimento.UkeyConhecimento);
                                        _cmd = _cmd.Replace("@CODIGO", OcorrenciaConhecimento.CodigoOcorrencia.ToString());
                                        _cmd = _cmd.Replace("@STATUS", "1");
                                        _cmd = _cmd.Replace("@typeRel", "2");


                                        //2017-11-29 15:51:29
                                        _cmd = _cmd.Replace("@DATA", String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now));
                                        _cmd = _cmd.Replace("@MENSAGEM", "Enviado Ok");

                                        ExecSql.execsqlCmd(_cmd);
                                    }
                                }
                                if (OcorrenciasEmAberto != null && OcorrenciasEmAberto.Count() != 0)
                                {
                                    foreach (var OcorrenciaConhecimento in OcorrenciasEmAberto.Where(x => x.LogRegister == 1).ToList())
                                    {
                                        var _cmd = "INSERT INTO OCORRENCIAS_ENVIADAS_ENTRADA_ENTREGA VALUES(@SEQ,'@UKEYCONHECIMENTO',@CODIGO,@STATUS,CONVERT(DATETIME,'@DATA',120),'@MENSAGEM',@typeRel)";

                                        _cmd = _cmd.Replace("@SEQ", OcorrenciaConhecimento.Seq.ToString());
                                        _cmd = _cmd.Replace("@UKEYCONHECIMENTO", OcorrenciaConhecimento.UkeyConhecimento);
                                        _cmd = _cmd.Replace("@CODIGO", OcorrenciaConhecimento.CodigoOcorrencia.ToString());
                                        _cmd = _cmd.Replace("@STATUS", "1");
                                        _cmd = _cmd.Replace("@typeRel", "2");


                                        //2017-11-29 15:51:29
                                        _cmd = _cmd.Replace("@DATA", String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now));
                                        _cmd = _cmd.Replace("@MENSAGEM", "Enviado Ok");

                                        ExecSql.execsqlCmd(_cmd);
                                    }
                                }
                            }
                            catch (Exception exRel2)
                            {
                                var erro = exRel2.Message;
                            }
                        }
                    }
                }
            }



            /***********Processo Selbetti layou propio*************************/
            new ProcessaSelBetti().Processar();
/*******************************************************************/

            /**************************************************************************/
            /*Grupo ELG sao 3 empresas, sao emails separados com arquivos por empresa*/
            List <Empresas> listaGrupoELG = new List <Empresas>();

            Empresas BITTENCOURT = new Empresas();

            //ukey do cadastro do cliente A03
            BITTENCOURT.CNPJ    = "FC23CED5_8E37_4F83_B";// " CNPJ 18125970000189";// - BITTENCOURT AUDIO E VIDEO EIRELI ME
            BITTENCOURT.relType = "4";
            BITTENCOURT.emails.Add("*****@*****.**");
            listaGrupoELG.Add(BITTENCOURT);

            Empresas ELG = new Empresas();

            ELG.CNPJ    = "STAR_NPZ43_2DG0UE35S";// CPNJ "05012368000193";// -ELG PEDESTAIS LTDA
            ELG.relType = "5";
            ELG.emails.Add("*****@*****.**");
            listaGrupoELG.Add(ELG);

            Empresas LP = new Empresas();

            LP.CNPJ    = "C72E5AA6-F339-4384-B"; // CNPJ "21851194000109";// -LP COMERCIO DE ELETRONICOS LTDA
            LP.relType = "6";
            LP.emails.Add("*****@*****.**");
            LP.emails.Add("*****@*****.**");

            listaGrupoELG.Add(LP);

            foreach (var empresas in listaGrupoELG.ToList())
            {
                new ProcessarELG().Processar(empresas);
            }
            /***************************************************************************************/
        }
コード例 #2
0
        /*Porque voce está ? vc tem uma demanda solicitada pelo Saulo, Cassia ou Deus?
         * se nao tem , nao mude nada nessa classe, pois podera cair sobre você uma terrivel maldição
         * se vc leu isso, vc está tendo uma chance de nao sofrer isso
         *
         *  Porém se vc teve a solicitação  das pessoas acima  Leia descrição do que essa classe faz
         *
         *  1ª  no metodo NeedSendToday recebe o parametro -1 que é a quantidade de Dias sem enviar o email, e vc ja percebeu aqui que
         *  essa classe manda email, nao so manda como envia com anexo, esse anexo é um xls, XLS NAO UM CSV.
         *  com as ocorrencias do Dia para empresa nessa caso Selbetti, na classe ProcessasELG ele manda para 3 empresas.
         *
         *
         */


        public void Processar()
        {
            WriteToAnEventLog log = new WriteToAnEventLog();

            if (NeedSendToday(-1))
            {
                var Ocorrencias = new List <OcorrenciaConhecimento>();

                try
                {
                    Ocorrencias = GenerateCSV();
                    if (Ocorrencias != null && Ocorrencias.Count() != 0)
                    {
                        var EmailToSend = RetornaConhecimento.GetEmailByConhecimentoUkey(Ocorrencias.FirstOrDefault().UkeyConhecimento);

                        var body = @"
                                    <strong>Atenção:</strong>
                                    Este é um envio de e-mail automático via sistema e não deve ser respondido.
                                    Qualquer dúvida, entre em contato diretamente com a Daytona Express 
                                    ";

                        using (var smtpClient = new SmtpClient("mail.daytonaexpress.com.br"))
                        {
                            smtpClient.UseDefaultCredentials = false;
                            smtpClient.Host        = "mail.daytonaexpress.com.br";
                            smtpClient.Port        = 587;
                            smtpClient.EnableSsl   = false;
                            smtpClient.Credentials = new NetworkCredential("*****@*****.**", "dayt@011");



                            var emailMensage = new MailMessage
                            {
                                IsBodyHtml = true,
                                From       = new MailAddress("*****@*****.**"),
                                Body       = body,
                                Subject    = "Informativo de Ocorrência",
                            };
                            //emailMensage.To.Add(new MailAddress(Email.EmailToSend));
                            //emailMensage.To.Add(new MailAddress(EmailToSend));
                            //emailMensage.To.Add(new MailAddress("*****@*****.**"));
                            //emailMensage.To.Add(new MailAddress("*****@*****.**"));

                            // e-mails atuais


                            // Alterado Joederli - 28/05/2019 - chamado 1490 - retirado e-mail transporte
                            //emailMensage.To.Add(new MailAddress("*****@*****.**"));
                            //emailMensage.To.Add(new MailAddress("*****@*****.**"));
                            emailMensage.To.Add(new MailAddress("*****@*****.**"));
                            emailMensage.To.Add(new MailAddress("*****@*****.**"));
                            emailMensage.To.Add(new MailAddress("*****@*****.**"));
                            emailMensage.To.Add(new MailAddress("*****@*****.**"));
                            emailMensage.To.Add(new MailAddress("*****@*****.**"));

                            // e-mail teste

                            //emailMensage.To.Add(new MailAddress("*****@*****.**"));

                            Attachment         attachment  = new Attachment(attachmentFilename, MediaTypeNames.Application.Octet);
                            ContentDisposition disposition = attachment.ContentDisposition;
                            disposition.CreationDate     = File.GetCreationTime(attachmentFilename);
                            disposition.ModificationDate = File.GetLastWriteTime(attachmentFilename);
                            disposition.ReadDate         = File.GetLastAccessTime(attachmentFilename);
                            disposition.FileName         = Path.GetFileName(attachmentFilename);
                            disposition.Size             = new FileInfo(attachmentFilename).Length;
                            disposition.DispositionType  = DispositionTypeNames.Attachment;
                            emailMensage.Attachments.Add(attachment);

                            smtpClient.Send(emailMensage);
                        }

                        foreach (var OcorrenciaConhecimento in Ocorrencias.Where(x => x.LogRegister == 1).ToList())
                        {
                            var _cmd = "INSERT INTO OCORRENCIAS_ENVIADAS_ENTRADA_ENTREGA VALUES(@SEQ,'@UKEYCONHECIMENTO',@CODIGO,@STATUS,CONVERT(DATETIME,'@DATA',120),'@MENSAGEM',NULL)";

                            _cmd = _cmd.Replace("@SEQ", OcorrenciaConhecimento.Seq.ToString());
                            _cmd = _cmd.Replace("@UKEYCONHECIMENTO", OcorrenciaConhecimento.UkeyConhecimento);
                            _cmd = _cmd.Replace("@CODIGO", OcorrenciaConhecimento.CodigoOcorrencia.ToString());
                            _cmd = _cmd.Replace("@STATUS", "1");

                            //2017-11-29 15:51:29
                            _cmd = _cmd.Replace("@DATA", String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now));
                            _cmd = _cmd.Replace("@MENSAGEM", "Enviado Ok");


                            // para não inerir o log

                            ExecSql.execsqlDr(_cmd);
                        }
                    }
                }
                catch (Exception e)
                {
                    log.RegistraLog("Erro processaEmail " + e.StackTrace, 3);
                }
            }
        }
コード例 #3
0
        public static void processaEmail()
        {
            WriteToAnEventLog log = new WriteToAnEventLog();

            if (DateTime.Now.DayOfWeek == DayOfWeek.Monday && DateTime.Now.Hour >= 17)
            {
                //  if(false)
                if (!WasSent(2))
                {
                    var A03_UKEYS = new List <string>
                    {
                        "F7CDA95A-A8E9-4C2B-B"
                    };


                    foreach (var A03_UKEY in A03_UKEYS)
                    {
                        var OcorrenciasConfirmadas = new List <OcorrenciaConhecimento>(); //Ocorrencias com entrega
                        var OcorrenciasEmAberto    = new List <OcorrenciaConhecimento>(); //Ocorrencias que não foram entregas

                        var FileNamePendente = string.Empty;

                        OcorrenciasEmAberto    = GenerateCSV2(0, A03_UKEY, "PENDENTE_");
                        FileNamePendente       = attachmentFilename;
                        OcorrenciasConfirmadas = GenerateCSV2(1, A03_UKEY, "ENVIO_7_DIAS_");


                        if ((OcorrenciasEmAberto != null && OcorrenciasEmAberto.Count() != 0) || (OcorrenciasConfirmadas != null && OcorrenciasConfirmadas.Count() != 0))
                        {
                            try
                            {
                                var EmailToSend = string.Empty;

                                if (OcorrenciasConfirmadas != null && OcorrenciasConfirmadas.Count() != 0)
                                {
                                    EmailToSend = RetornaConhecimento.GetEmailByConhecimentoUkey(OcorrenciasConfirmadas.FirstOrDefault().UkeyConhecimento);
                                }
                                else if (OcorrenciasEmAberto != null && OcorrenciasEmAberto.Count() != 0)
                                {
                                    EmailToSend = RetornaConhecimento.GetEmailByConhecimentoUkey(OcorrenciasEmAberto.FirstOrDefault().UkeyConhecimento);
                                }
                                else
                                {
                                    throw new Exception("Nenhuma ocorrencia encontrada para buscar email de enivo! Entre em contato com o desenvolvedor!");
                                }


                                var body = @"
                                            <strong>Atenção:</strong>
                                            Este é um envio de e-mail automático via sistema e não deve ser respondido.
                                            Qualquer dúvida, entre em contato diretamente com a Daytona Express 
                                            ";

                                using (var smtpClient = new SmtpClient("mail.daytonaexpress.com.br"))
                                {
                                    smtpClient.UseDefaultCredentials = false;
                                    smtpClient.Host        = "mail.daytonaexpress.com.br";
                                    smtpClient.Port        = 587;
                                    smtpClient.EnableSsl   = false;
                                    smtpClient.Credentials = new NetworkCredential("*****@*****.**", "dayt@011");



                                    var emailMensage = new MailMessage
                                    {
                                        IsBodyHtml = true,
                                        From       = new MailAddress("*****@*****.**"),
                                        Body       = body,
                                        Subject    = "Informativo de Ocorrência",
                                    };
                                    //emailMensage.To.Add(new MailAddress(Email.EmailToSend));
                                    //emailMensage.To.Add(new MailAddress(EmailToSend));
                                    //emailMensage.To.Add(new MailAddress("*****@*****.**"));
                                    //emailMensage.To.Add(new MailAddress("*****@*****.**"));
                                    emailMensage.To.Add(new MailAddress("*****@*****.**"));
                                    emailMensage.To.Add(new MailAddress("*****@*****.**"));
                                    emailMensage.To.Add(new MailAddress("*****@*****.**"));


                                    try
                                    {
                                        if (OcorrenciasConfirmadas != null && OcorrenciasConfirmadas.Count() != 0)
                                        {
                                            Attachment         attachment  = new Attachment(attachmentFilename, MediaTypeNames.Application.Octet);
                                            ContentDisposition disposition = attachment.ContentDisposition;
                                            disposition.CreationDate     = File.GetCreationTime(attachmentFilename);
                                            disposition.ModificationDate = File.GetLastWriteTime(attachmentFilename);
                                            disposition.ReadDate         = File.GetLastAccessTime(attachmentFilename);
                                            disposition.FileName         = Path.GetFileName(attachmentFilename);
                                            disposition.Size             = new FileInfo(attachmentFilename).Length;
                                            disposition.DispositionType  = DispositionTypeNames.Attachment;
                                            emailMensage.Attachments.Add(attachment);
                                        }
                                        if (OcorrenciasEmAberto != null && OcorrenciasEmAberto.Count() != 0)
                                        {
                                            Attachment         attachmentPendente = new Attachment(FileNamePendente, MediaTypeNames.Application.Octet);
                                            ContentDisposition disposition        = attachmentPendente.ContentDisposition;
                                            disposition.CreationDate     = File.GetCreationTime(FileNamePendente);
                                            disposition.ModificationDate = File.GetLastWriteTime(FileNamePendente);
                                            disposition.ReadDate         = File.GetLastAccessTime(FileNamePendente);
                                            disposition.FileName         = Path.GetFileName(FileNamePendente);
                                            disposition.Size             = new FileInfo(FileNamePendente).Length;
                                            disposition.DispositionType  = DispositionTypeNames.Attachment;
                                            emailMensage.Attachments.Add(attachmentPendente);
                                        }


                                        smtpClient.Send(emailMensage);
                                    }
                                    catch (Exception e)
                                    {
                                        log.RegistraLog("Erro processaEmail " + e.StackTrace, 3);
                                    }
                                }


                                if (OcorrenciasConfirmadas != null && OcorrenciasConfirmadas.Count() != 0)
                                {
                                    foreach (var OcorrenciaConhecimento in OcorrenciasConfirmadas.Where(x => x.LogRegister == 1).ToList())
                                    {
                                        var _cmd = "INSERT INTO  OCORRENCIAS_ENVIADAS_ENTRADA_ENTREGA  VALUES(@SEQ,'@UKEYCONHECIMENTO',@CODIGO,@STATUS,CONVERT(DATETIME,'@DATA',120),'@MENSAGEM',@typeRel)";

                                        _cmd = _cmd.Replace("@SEQ", OcorrenciaConhecimento.Seq.ToString());
                                        _cmd = _cmd.Replace("@UKEYCONHECIMENTO", OcorrenciaConhecimento.UkeyConhecimento);
                                        _cmd = _cmd.Replace("@CODIGO", OcorrenciaConhecimento.CodigoOcorrencia.ToString());
                                        _cmd = _cmd.Replace("@STATUS", "1");
                                        _cmd = _cmd.Replace("@typeRel", "2");


                                        //2017-11-29 15:51:29
                                        _cmd = _cmd.Replace("@DATA", String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now));
                                        _cmd = _cmd.Replace("@MENSAGEM", "Enviado Ok");

                                        ExecSql.execsqlCmd(_cmd);
                                    }
                                }
                                if (OcorrenciasEmAberto != null && OcorrenciasEmAberto.Count() != 0)
                                {
                                    foreach (var OcorrenciaConhecimento in OcorrenciasEmAberto.Where(x => x.LogRegister == 1).ToList())
                                    {
                                        var _cmd = "INSERT INTO OCORRENCIAS_ENVIADAS_ENTRADA_ENTREGA VALUES(@SEQ,'@UKEYCONHECIMENTO',@CODIGO,@STATUS,CONVERT(DATETIME,'@DATA',120),'@MENSAGEM',@typeRel)";

                                        _cmd = _cmd.Replace("@SEQ", OcorrenciaConhecimento.Seq.ToString());
                                        _cmd = _cmd.Replace("@UKEYCONHECIMENTO", OcorrenciaConhecimento.UkeyConhecimento);
                                        _cmd = _cmd.Replace("@CODIGO", OcorrenciaConhecimento.CodigoOcorrencia.ToString());
                                        _cmd = _cmd.Replace("@STATUS", "1");
                                        _cmd = _cmd.Replace("@typeRel", "2");


                                        //2017-11-29 15:51:29
                                        _cmd = _cmd.Replace("@DATA", String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now));
                                        _cmd = _cmd.Replace("@MENSAGEM", "Enviado Ok");

                                        ExecSql.execsqlCmd(_cmd);
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                log.RegistraLog("Erro processaEmail " + e.StackTrace, 3);
                            }
                        }
                    }
                }
            }



            try
            {
                /********** EDI*********************************/
                new ProcessaEDI().Processar();
                /**************************************************/



                /***********Processo Selbetti layou propio*************************/
                new ProcessaSelBetti().Processar();
                /*******************************************************************/

                /**************************************************************************/
                /*Grupo ELG sao 3 empresas, sao emails separados com arquivos por empresa*/
                List <Empresas> listaempresa = new List <Empresas>();
                //retorna lista de e-clientes e e-mails
                listaempresa = GetEmails();


                foreach (var empresas in listaempresa.ToList())
                {
                    new ProcessarELG().Processar(empresas);
                }
            }
            catch (Exception e)
            {
                log.RegistraLog("Erro processaEmail " + e.StackTrace, 3);
            }
            /***************************************************************************************/
        }