示例#1
0
        private void CreateMailWithAttachmentNr6(string officialPositionWhoGetNewNotification, string numberLastNotification, string attachmentPath)
        {
            System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("OUTLOOK");
            int collCount = processes.Length;

            if (collCount != 0)
            {
                Microsoft.Office.Interop.Outlook.Application oApp     = Marshal.GetActiveObject("Outlook.Application") as Microsoft.Office.Interop.Outlook.Application;
                Microsoft.Office.Interop.Outlook.MailItem    mailItem = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
                mailItem.Subject = "PIW Olesno - zgłoszenia padniecia numer " + "1608/" + numberLastNotification + "/2019" + ".";
                if (mainWindow.comboBox_UtilizationCompany.Text == "Jasta")
                {
                    mailItem.To = "[email protected], [email protected]";
                    mailItem.CC = "radomsko.piw @wetgiw.gov.pl, [email protected], [email protected]";
                }
                else if (mainWindow.comboBox_UtilizationCompany.Text == "Farmutil")
                {
                    mailItem.To = "*****@*****.**";
                    mailItem.CC = "[email protected], [email protected], [email protected]";
                }
                else
                {
                    mailItem.To = " ";
                }
                mailItem.Body = "Zgłoszenie padnięcia nr " + "1608/" + numberLastNotification + "/2019" + ". \nPIW Olesno\n" + officialPositionWhoGetNewNotification + "\n" + mainWindow.comboBox_WhoGetGetNotification.Text;
                Microsoft.Office.Interop.Outlook.Attachments mailAttachments = mailItem.Attachments;
                Microsoft.Office.Interop.Outlook.Attachment  newAttachment   = mailAttachments.Add(
                    attachmentPath + numberLastNotification + "-" + mainWindow.txtFarmNumber.Text + "-zal6-" + savingDateTime + ".pdf",
                    Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, 1, "Załącznik nr 6");
                mailItem.Save();
                mailItem.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceNormal;
                mailItem.Display(false);
                mailItem = null;
                oApp     = null;
                MessageBox.Show("Utworzono wiadomość z załącznikiem nr 6.");
            }
        }
示例#2
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);
                }
            }
        }