public async override Task RunCommand(object sender)
        {
            var      engine    = (IAutomationEngineInstance)sender;
            MailItem vMailItem = (MailItem)await v_MailItem.EvaluateCode(engine);

            var vDestinationFolder = (string)await v_DestinationFolder.EvaluateCode(engine);

            Application outlookApp = new Application();
            NameSpace   test       = outlookApp.GetNamespace("MAPI");

            test.Logon("", "", false, true);
            AddressEntry currentUser = outlookApp.Session.CurrentUser.AddressEntry;

            if (currentUser.Type == "EX")
            {
                MAPIFolder inboxFolder       = (MAPIFolder)test.GetDefaultFolder(OlDefaultFolders.olFolderInbox).Parent;
                MAPIFolder destinationFolder = inboxFolder.Folders[vDestinationFolder];

                if (v_OperationType == "Move MailItem")
                {
                    if (v_MoveCopyUnreadOnly == "Yes")
                    {
                        if (vMailItem.UnRead == true)
                        {
                            vMailItem.Move(destinationFolder);
                        }
                    }
                    else
                    {
                        vMailItem.Move(destinationFolder);
                    }
                }
                else if (v_OperationType == "Copy MailItem")
                {
                    MailItem copyMail;

                    if (v_MoveCopyUnreadOnly == "Yes")
                    {
                        if (vMailItem.UnRead == true)
                        {
                            copyMail = (MailItem)vMailItem.Copy();
                            copyMail.Move(destinationFolder);
                        }
                    }
                    else
                    {
                        copyMail = (MailItem)vMailItem.Copy();
                        copyMail.Move(destinationFolder);
                    }
                }
            }
        }
Пример #2
0
        public override void RunCommand(object sender)
        {
            var      engine             = (IAutomationEngineInstance)sender;
            MailItem vMailItem          = (MailItem)v_MailItem.ConvertUserVariableToObject(engine, nameof(v_MailItem), this);
            var      vDestinationFolder = v_DestinationFolder.ConvertUserVariableToString(engine);

            Application  outlookApp  = new Application();
            AddressEntry currentUser = outlookApp.Session.CurrentUser.AddressEntry;
            NameSpace    test        = outlookApp.GetNamespace("MAPI");

            if (currentUser.Type == "EX")
            {
                MAPIFolder inboxFolder       = (MAPIFolder)test.GetDefaultFolder(OlDefaultFolders.olFolderInbox).Parent;
                MAPIFolder destinationFolder = inboxFolder.Folders[vDestinationFolder];

                if (v_OperationType == "Move MailItem")
                {
                    if (v_MoveCopyUnreadOnly == "Yes")
                    {
                        if (vMailItem.UnRead == true)
                        {
                            vMailItem.Move(destinationFolder);
                        }
                    }
                    else
                    {
                        vMailItem.Move(destinationFolder);
                    }
                }
                else if (v_OperationType == "Copy MailItem")
                {
                    MailItem copyMail = null;
                    if (v_MoveCopyUnreadOnly == "Yes")
                    {
                        if (vMailItem.UnRead == true)
                        {
                            copyMail = (MailItem)vMailItem.Copy();
                            copyMail.Move(destinationFolder);
                        }
                    }
                    else
                    {
                        copyMail = (MailItem)vMailItem.Copy();
                        copyMail.Move(destinationFolder);
                    }
                }
            }
        }
Пример #3
0
        public void SendMail(MailItem mailItem)
        {
            if (mailItem.FlagRequest == MailServiceSettings.CopyMailFlag)
            {
                MAPIFolder folder = _Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
                mailItem.Move(folder);
                return;
            }
            if (mailItem.FlagRequest != MailServiceSettings.AutoMailFlag)
            {
                string to = $"{mailItem.To}; {mailItem.CC}";

                Outlook.Folder selectedFolder = StartDialogService();
                if (selectedFolder != null)
                {
                    mailItem.SaveSentMessageFolder = selectedFolder;
                    mailItem.Save();
                    MailItem copyMail = mailItem.Copy();
                    copyMail.FlagRequest = MailServiceSettings.CopyMailFlag;
                    copyMail.Save();
                    SendToRecipients(to);
                }
            }
            mailItem.Send();
        }
Пример #4
0
        public void AddMailItems(MailItem mailItem, string folderName = "")
        {
            folderName = folderName ?? "Temp_" + PSTName;

            MAPIFolder destFolder = GetFolder(folderName);

            MailItem tempMailItem = mailItem.Copy();

            tempMailItem.Move(destFolder);
        }
Пример #5
0
        public string IncomeMail(MailItem mailItem)
        {
            mailItem.UnRead = true;
            mailItem.Save();

            Outlook.Folder selectedFolder = StartDialogService();
            if (selectedFolder != null)
            {
                MailItem copyMail = mailItem.Copy();
                copyMail.Move(selectedFolder);
            }
            return(mailItem.EntryID);
        }
Пример #6
0
        private void GetAttachmentsFromConversation(MailItem mailItem)
        {
            if (mailItem == null)
            {
                return;
            }

            if (mailItem.Attachments.CountNonEmbeddedAttachments() > 0)
            {
                return;
            }

            System.Collections.Generic.Stack <MailItem> st = new System.Collections.Generic.Stack <MailItem>();

            // Determine the store of the mail item.
            Outlook.Folder folder = mailItem.Parent as Outlook.Folder;
            Outlook.Store  store  = folder.Store;
            if (store.IsConversationEnabled == true)
            {
                // Obtain a Conversation object.
                Outlook.Conversation conv = mailItem.GetConversation();
                // Check for null Conversation.
                if (conv != null)
                {
                    // Obtain Table that contains rows
                    // for each item in the conversation.
                    Outlook.Table table = conv.GetTable();
                    _logger.Debug("Conversation Items Count: " + table.GetRowCount().ToString());
                    _logger.Debug("Conversation Items from Root:");

                    // Obtain root items and enumerate the conversation.
                    Outlook.SimpleItems simpleItems = conv.GetRootItems();
                    foreach (object item in simpleItems)
                    {
                        // In this example, enumerate only MailItem type.
                        // Other types such as PostItem or MeetingItem
                        // can appear in the conversation.
                        if (item is Outlook.MailItem)
                        {
                            Outlook.MailItem mail     = item as Outlook.MailItem;
                            Outlook.Folder   inFolder = mail.Parent as Outlook.Folder;
                            string           msg      = mail.Subject + " in folder [" + inFolder.Name + "] EntryId [" + (mail.EntryID.ToString() ?? "NONE") + "]";
                            _logger.Debug(msg);
                            _logger.Debug(mail.Sender);
                            _logger.Debug(mail.ReceivedByEntryID);

                            if (mail.EntryID != null && (mail.Sender != null || mail.ReceivedByEntryID != null))
                            {
                                st.Push(mail);
                            }
                        }
                        // Call EnumerateConversation
                        // to access child nodes of root items.
                        EnumerateConversation(st, item, conv);
                    }
                }
            }

            while (st.Count > 0)
            {
                MailItem it = st.Pop();

                if (it.Attachments.CountNonEmbeddedAttachments() > 0)
                {
                    //_logger.Debug(it.Attachments.CountNonEmbeddedAttachments());

                    try
                    {
                        if (mailItem.IsMailItemSignedOrEncrypted())
                        {
                            if (MessageBox.Show(null, "Es handelt sich um eine signierte Nachricht. Soll diese für die Anhänge ohne Zertifikat dupliziert werden?", "Nachricht duplizieren?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                                mailItem.Close(OlInspectorClose.olDiscard);
                                mailItem = mailItem.Copy();
                                mailItem.Unsign();
                                mailItem.Save();
                                mailItem.Close(OlInspectorClose.olDiscard);
                                mailItem.Save();
                            }
                            else
                            {
                                st.Clear();
                                break;
                            }
                        }

                        mailItem.CopyAttachmentsFrom(it);
                        mailItem.Save();
                    }
                    catch (System.Exception ex)
                    {
                        //mailItem.Close(OlInspectorClose.olDiscard);
                        MessageBox.Show(ex.Message);
                    }

                    st.Clear();
                }
            }
            st.Clear();

            Marshal.ReleaseComObject(mailItem);
        }
Пример #7
0
        public override void RunCommand(object sender)
        {
            var engine             = (Engine.AutomationEngineInstance)sender;
            var vSourceFolder      = v_SourceFolder.ConvertToUserVariable(sender);
            var vFilter            = v_Filter.ConvertToUserVariable(sender);
            var vDestinationFolder = v_DestinationFolder.ConvertToUserVariable(sender);

            Application  outlookApp  = new Application();
            AddressEntry currentUser = outlookApp.Session.CurrentUser.AddressEntry;
            NameSpace    test        = outlookApp.GetNamespace("MAPI");

            if (currentUser.Type == "EX")
            {
                MAPIFolder inboxFolder       = test.GetDefaultFolder(OlDefaultFolders.olFolderInbox).Parent;
                MAPIFolder sourceFolder      = inboxFolder.Folders[vSourceFolder];
                MAPIFolder destinationFolder = inboxFolder.Folders[vDestinationFolder];
                Items      filteredItems     = null;

                if (vFilter != "")
                {
                    filteredItems = sourceFolder.Items.Restrict(vFilter);
                }
                else
                {
                    filteredItems = sourceFolder.Items;
                }

                foreach (object _obj in filteredItems)
                {
                    if (_obj is MailItem)
                    {
                        MailItem tempMail = (MailItem)_obj;
                        if (v_OperationType == "Move Emails")
                        {
                            if (v_MoveUnreadOnly == "Yes")
                            {
                                if (tempMail.UnRead == true)
                                {
                                    tempMail.Move(destinationFolder);
                                }
                            }
                            else
                            {
                                tempMail.Move(destinationFolder);
                            }
                        }
                        else if (v_OperationType == "Copy Emails")
                        {
                            MailItem copyMail = null;
                            if (v_MoveUnreadOnly == "Yes")
                            {
                                if (tempMail.UnRead == true)
                                {
                                    copyMail = tempMail.Copy();
                                    copyMail.Move(destinationFolder);
                                }
                            }
                            else
                            {
                                copyMail = tempMail.Copy();
                                copyMail.Move(destinationFolder);
                            }
                        }
                    }
                }
            }
        }