示例#1
0
            public void SendMailTicket(int idTicket, string clave, string body, string to)
            {
                try
                {
                    MailClient oClient = GetMailClient();
                    Smtp.SendNotificationTicketGenerated(idTicket, clave, body, to);

                    oClient.Quit();
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
示例#2
0
            public string GetMails()
            {
                StringBuilder result = new StringBuilder();

                try
                {
                    result.AppendLine("Conecta con correo");
                    MailClient oClient = GetMailClient();
                    result.AppendLine("Conexión exitosa");
                    result.AppendLine("Obtiene correos nuevos");
                    MailInfo[] infoMails = oClient.GetMailInfos();

                    if (infoMails != null)
                    {
                        result.AppendLine(string.Format("Se encontraron {0} correos nuevos", infoMails.Length));
                        foreach (MailInfo infoMail in infoMails)
                        {
                            Mail oMail = null;
                            try
                            {
                                oMail = oClient.GetMail(infoMail);
                                List <string> headersIngored = new List <string>
                                {
                                    "Auto-Submitted",
                                    "X-Auto-Response-Suppress",
                                    "Precedence"
                                };
                                result.AppendLine(string.Format("Procesando correo {0} recibido {1}", oMail.Subject, oMail.ReceivedDate));
                                bool correovalido = true;
                                foreach (string header in headersIngored)
                                {
                                    correovalido = ValidaHeader(oMail.Headers.GetValueOfKey(header), _valuesIgnored);
                                    if (!correovalido)
                                    {
                                        break;
                                    }
                                }

                                if (correovalido)
                                {
                                    result.AppendLine(string.Format("Correo {0} recibido {1} procesado como nuevo", oMail.Subject, oMail.ReceivedDate));
                                    if (string.IsNullOrEmpty(oMail.Headers.GetValueOfKey("References")))
                                    {
                                        result.AppendLine(string.Format("Correo {0} recibido {1} procesado como nuevo", oMail.Subject, oMail.ReceivedDate));
                                        Smtp.SendNotificationNewTicket(oMail);
                                    }
                                    else
                                    {
                                        result.AppendLine(string.Format("Correo {0} recibido {1} procesado como comentario", oMail.Subject, oMail.ReceivedDate));
                                        string   references      = oMail.Headers.GetValueOfKey("References");
                                        string[] referencesArray = references.Split('~');
                                        if (referencesArray.Any(w => w.Contains("ticket")))
                                        {
                                            Smtp.SendNotificationCommentTicket(oMail);
                                        }
                                        else
                                        {
                                            Smtp.SendNotificationNewTicket(oMail);
                                        }
                                    }
                                }
                                else
                                {
                                    result.AppendLine(string.Format("Correo {0} recibido {1} se descarto por motivo de autorespuesa", oMail.Subject, oMail.ReceivedDate));
                                }
                                ManagerMessage.MarcarLeidoNoLeido(oClient, infoMail);
                            }
                            catch (Exception e)
                            {
                                if (oMail != null)
                                {
                                    result.AppendLine("error al recibir correo: " + oMail.Subject);
                                }
                                else
                                {
                                    result.AppendLine("error al recibir correo: " + e.Message);
                                }
                            }
                        }
                    }
                    oClient.Quit();
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
                return(result.ToString().Trim());
            }