Esempio n. 1
0
    private Microsoft.Office.Interop.Outlook.Items GetAppointmentsInRange(
        Microsoft.Office.Interop.Outlook.Folder folder, DateTime startTime, DateTime endTime)
    {
        string filter = "[Start] >= '" + startTime.ToString("g") + "' AND [End] <= '" + endTime.ToString("g") + "'";

        //Response.Write(filter);
        try
        {
            Microsoft.Office.Interop.Outlook.Items calItems = folder.Items;
            calItems.IncludeRecurrences = true;
            calItems.Sort("[Start]", Type.Missing);
            Microsoft.Office.Interop.Outlook.Items restrictItems = calItems.Restrict(filter);
            if (restrictItems.Count > 0)
            {
                return(restrictItems);
            }
            else
            {
                return(null);
            }
        }
        catch
        {
            return(null);
        }
    }
Esempio n. 2
0
        private static Appointment LookForNextAppointment(string textToSearch)
        {
            Microsoft.Office.Interop.Outlook.Application oApp = null;
            Microsoft.Office.Interop.Outlook.NameSpace mapiNamespace = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder CalendarFolder = null;
            Microsoft.Office.Interop.Outlook.Items outlookCalendarItems = null;

            oApp = new Microsoft.Office.Interop.Outlook.Application();
            mapiNamespace = oApp.GetNamespace("MAPI"); ;
            CalendarFolder = mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
            outlookCalendarItems = CalendarFolder.Items;
            outlookCalendarItems.Sort("[Start]");
            var now = DateTime.Now.Date.ToString("g");
            var nowIn1Year = DateTime.Now.Date.AddYears(1).ToString("g");
            outlookCalendarItems = outlookCalendarItems.Restrict($"[Start] >= \"{now}\" AND [End] < \"{nowIn1Year}\" ");

            foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
            {
                var subject = item.Subject;
                if (subject.IndexOf(textToSearch,StringComparison.InvariantCultureIgnoreCase)!=-1)
                {
                    return new Appointment() { Subject = subject, Start = item.Start };
                }
            }
            return null;
        }
Esempio n. 3
0
        private void InitOutlookService()
        {
            if (!ifAlreadyInit)
            {
                oApp          = new Microsoft.Office.Interop.Outlook.Application();
                mapiNamespace = oApp.GetNamespace("MAPI");
                ;
                calendarFolder =
                    mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
                outlookCalendarItems = calendarFolder.Items;

                outlookCalendarItems.Sort("[Start]");
                outlookCalendarItems.IncludeRecurrences = true;

                string s1           = GetDateInString(minTime);
                string s2           = GetDateInString(maxTime);
                var    filterString = "[Start] >= '" + s1 + "' AND [End] < '" + s2 + "'";
                outlookCalendarItems = outlookCalendarItems.Restrict(filterString);
                ifAlreadyInit        = true;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Metodo que descarga los archivos adjuntos de los correos
        /// no leidos de la cuenta de outlook
        /// </summary>
        public void bandejaEntradaOutlook()
        {
            Microsoft.Office.Interop.Outlook.Application app         = null;
            Microsoft.Office.Interop.Outlook._NameSpace  ns          = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder  inboxFolder = null;
            Microsoft.Office.Interop.Outlook.MailItem    sinLeer;

            int p = 0, t = 0;

            while (!detenerHilo)
            {
                try
                {
                    app = new Microsoft.Office.Interop.Outlook.Application();

                    ns = app.GetNamespace("MAPI");
                    ns.Logon(null, null, false, false);

                    inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.
                                                      OlDefaultFolders.olFolderInbox);

                    ///Se obtiene la bandeja de entrada de la cuenta de correo
                    Microsoft.Office.Interop.Outlook.Items inboxItems = inboxFolder.Items;

                    t = inboxFolder.UnReadItemCount;

                    ///Se obtiene la bandeja de entrada de correos no leidos
                    inboxItems = inboxItems.Restrict("[unread] = true");

                    while (p < t)
                    {
                        if (p == 0)
                        {
                            ///Se obtiene el primer elemento de la bandeja de entrada
                            sinLeer = inboxItems.GetFirst();
                        }
                        else
                        {
                            ///Se obtiene el elemento siguiente de la bandeja de entrada
                            sinLeer = inboxItems.GetNext();
                        }

                        ///Se obtiene los archivos adjuntos del correo
                        Microsoft.Office.Interop.Outlook.Attachments adjuntos = sinLeer.Attachments;

                        foreach (Microsoft.Office.Interop.Outlook.Attachment archivo in adjuntos)
                        {
                            if (ValidarXmlSobre(archivo.FileName))
                            {
                                ///Se marca el correo como no leido
                                sinLeer.UnRead = false;

                                //Se descargar el archivo adjunto del correo
                                archivo.SaveAsFile(RutasCarpetas.RutaCarpetaBandejaEntrada + archivo.FileName);
                                string desde = sinLeer.Sender.ToString();

                                //Se sube el archivo al servidor FTP
                                FTP ftp = new FTP();
                                ftp.CargarArchivos(archivo.FileName, RutasCarpetas.RutaCarpetaBandejaEntrada, 3);

                                //Se guarda en la tabla de sobres Recibidos

                                respuestaSobre.GenerarXML(RutasCarpetas.RutaCarpetaBandejaEntrada, archivo.FileName, desde);
                            }
                            //Se comprueba que sea un ACK
                            else if (ValidarXmlACKSobre(archivo.FileName))
                            {
                                archivo.SaveAsFile(RutasCarpetas.RutaCarpetaBandejaEntrada);
                                sinLeer.UnRead = false;

                                SobreTransito         sobreTransito      = ObtenerSobreTransito(archivo.FileName, sinLeer.Sender.ToString());
                                ManteUdoSobreTransito manteSobreTransito = new ManteUdoSobreTransito();
                                manteSobreTransito.Almacenar(sobreTransito);
                            }
                        }
                        p = p + 1;
                    }
                }
                catch (Exception)
                {
                }
                finally
                {
                    ns          = null;
                    app         = null;
                    inboxFolder = null;

                    Thread.Sleep(60000);
                }
            }
        }
        public void readingUnReadMailsAsync(Microsoft.Office.Interop.Outlook.Items inboxItems)
        {
            if (myInbox.Items.Count > 0)
            {
                Microsoft.Office.Interop.Outlook.Items items = myInbox.Items;
                inboxItems = inboxItems.Restrict("[UnRead] = true");
                Console.WriteLine(string.Format("Total Unread message {0}:", inboxItems.Count));
                int x = 0;

                foreach (Microsoft.Office.Interop.Outlook.MailItem item in inboxItems)
                {
                    var attachments = item.Attachments;
                    var urlhtml     = item.HTMLBody;

                    string Textbody = item.Body;
                    var    matches  = Regex.Matches(urlhtml, @"<a\shref=""(?<url>.*?)"">(?<text>.*?)</a>");
                    if (attachments.Count != 0)
                    {
                        new LogFile().Writelog("Unread Mail from your inbox :-");
                        ++x;
                        Console.WriteLine("{0} Unread Mail from your inbox", ++x);
                        new LogFile().Writelog("            x");
                        new LogFile().Writelog("from:-");
                        string SenderName = item.SenderName;
                        new LogFile().Writelog("SenderName");
                        string ReceiverName = item.ReceivedByName;
                        new LogFile().Writelog("ReceiverName");
                        string Subject = item.Subject;
                        new LogFile().Writelog("Subject");
                        Console.WriteLine(string.Format("from:-     {0}", item.SenderName));
                        Console.WriteLine(string.Format("To:-     {0}", item.ReceivedByName));
                        Console.WriteLine(string.Format("Subject:-     {0}", item.Subject));
                        // Console.WriteLine(string.Format("Message:-     {0}", item.Body));
                        for (int i = 1; i <= attachments.Count; i++)
                        {
                            new LogFile().Writelog("Attachments:-");
                            string Attachments = item.Attachments[i].FileName;
                            new LogFile().Writelog("Attachments");
                            file = Path.GetFullPath(item.Attachments[i].FileName);
                            new VirusChecking().processVirusTotal(file, item, ScanUrl, matches);
                        }
                    }
                    else if (matches.Count != 0)
                    {
                        foreach (Match url in matches)
                        {
                            ScanUrl = url.Groups["url"].Value;
                            new VirusChecking().processVirusTotal(file, item, ScanUrl, matches);
                        }
                    }
                    else
                    {
                        string   path     = @"C:\Users\10653836\Desktop\dll.txt";
                        string[] contents = File.ReadAllLines(path);
                        if (contents.Any(item.Subject.Contains))
                        {
                            new VirusChecking().MoveAttactment(item);
                        }
                    }
                }
            }
        }