// CopyTo CopyFolder GetNuffer TellVersion Destination
        public void NewMailAndMoveToSubPublicFolder()
        {
            // Create a simple mail and save
            Outlook.MailItem omailOne = Utilities.CreateSimpleEmail("FastTransferCopyTo");
            omailOne.Save();
            // Create a simple mail and save
            Outlook.MailItem omailTwo = Utilities.CreateSimpleEmail("FastTransferCopyTo");
            omailTwo.Save();
            // Get first user folder in All public folder
            publicFolders = oApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olPublicFoldersAllPublicFolders);
            Outlook.MAPIFolder firstUserFolder = Utilities.GetUserFolderInAllPublicFolder(publicFolders);
            // Add a subfoler named testFolder under the firstUserFolder
            Outlook.MAPIFolder testFolder = Utilities.AddSubFolder(firstUserFolder, "testFolder");
            // Move the new created mail to public folder
            omailOne.Copy().Move(testFolder);
            omailTwo.Copy().Move(testFolder);
            testFolder.CopyTo(inboxFolders);
            // Delete all subfolders in firstUserFolder
            Utilities.RemoveAllSubFolders(firstUserFolder, false);
            // Delete all subfolders in inboxFolders
            Utilities.RemoveAllSubFolders(inboxFolders, false);
            bool result = MessageParser.ParseMessage();

            Assert.IsTrue(result, "Case failed, check the details information in error.txt file.");
        }
        public int createOutputFile(Recepient recepient, String outputDir, String attachmentDirectory)
        {
            int createdFiles = 0;

            try
            {
                Outlook.MailItem result   = (Outlook.MailItem)mailItem.Copy();
                String           htmlBody = result.HTMLBody;
                String           pattern  = "<span class=SpellE>.*</span>";
                String           toReplace;
                foreach (Match m in Regex.Matches(htmlBody, pattern))
                {
                    toReplace = m.Value.Replace("<span class=SpellE>", String.Empty).Replace("</span>", String.Empty);
                    htmlBody  = htmlBody.Replace(m.Value, toReplace);
                }
                String subject = recepient.Subject != null ? recepient.Subject : result.Subject;
                foreach (string key in recepient.FieldsToReplace.Keys)
                {
                    string mappedValue = (string)recepient.FieldsToReplace[key];
                    htmlBody = htmlBody.Replace(key, mappedValue);
                    // result.Subject=result.Subject.Replace(key, (string)recepient.FieldsToReplace[key]);
                    subject = subject.Replace(key, mappedValue);
                }
                result.HTMLBody = htmlBody;
                result.Subject  = subject;
                String resultPath = outputDir + "\\" + recepient.EmployeeID + ".msg";
                result.To = recepient.EmailAddress;
                if (recepient.Cc != null)
                {
                    result.CC = recepient.Cc;
                }
                if (recepient.Bcc != null)
                {
                    result.BCC = recepient.Bcc;
                }
                if (attachmentDirectory != null)
                {
                    string[] fileArray = Directory.GetFiles(attachmentDirectory);
                    foreach (String filename in fileArray)
                    {
                        if (filename.Contains(recepient.EmployeeID))
                        {
                            result.Attachments.Add(filename);
                        }
                    }
                }
                // if(acc!=null) result.SendUsingAccount = acc;
                //result.Sender = acc.DisplayName;
                MailList.Add(result);
                result.SaveAs(resultPath);
                createdFiles++;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error creating Excel file for " + recepient.EmployeeID, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(createdFiles);
            }
            return(createdFiles);
        }
        public void NewMailAndMoveToSubPublicFolder()
        {
            // Create a simple mail and save
            Outlook.MailItem omailOne = Utilities.CreateSimpleEmail("FastTransferCopyTo");
            omailOne.Save();

            // Create a simple mail and save
            Outlook.MailItem omailTwo = Utilities.CreateSimpleEmail("FastTransferCopyTo");
            omailTwo.Save();

            // Get first user folder in All public folder
            TestBase.publicFolders = outlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olPublicFoldersAllPublicFolders);
            Outlook.MAPIFolder firstUserFolder = Utilities.GetUserFolderInAllPublicFolder(TestBase.publicFolders);

            // Add a sub-folder named testFolder under the firstUserFolder
            Outlook.MAPIFolder testFolder = Utilities.AddSubFolder(firstUserFolder, "testFolder");

            // Move the new created mail to public folder
            omailOne.Copy().Move(testFolder);
            omailTwo.Copy().Move(testFolder);
            testFolder.CopyTo(TestBase.inboxFolders);

            // Delete all sub-folders in firstUserFolder
            Utilities.RemoveAllSubFolders(firstUserFolder, false);

            // Delete all sub-folders in inboxFolders
            Utilities.RemoveAllSubFolders(TestBase.inboxFolders, false);

            // Parse the saved trace using MAPI Inspector
            List <string> allRopLists = new List <string>();
            bool          result      = MessageParser.ParseMessage(out allRopLists);

            // Update the XML file for the covered message
            Utilities.UpdateXMLFile(allRopLists);

            // Assert failed if the parsed result has error
            Assert.IsTrue(result, "Case failed, check the details information in error.txt file.");
        }
Example #4
0
        private void bt_NewPassMail_Click(object sender, RibbonControlEventArgs e)
        {
            if (this.CompressSettings.Count == 0)
            {
                return;
            }
            var listList    = new List <string>();
            var settingsMap = this.CompressSettings.ToDictionary(i => Path.GetFileName(i.CompressFilePath));

            foreach (var attachment in mailItem.Attachments.Cast <Attachment>())
            {
                if (settingsMap.ContainsKey(attachment.FileName) == true && settingsMap[attachment.FileName].HasPassword == true)
                {
                    var setting = settingsMap[attachment.FileName];
                    var line    = string.Format("ファイル名:{0}\r\nパスワード:{1}\r\n", attachment.FileName, setting.PasswordText);
                    listList.Add(line);
                }
            }

            if (listList.Count != 0)
            {
                Outlook.MailItem mail = mailItem.Copy();
                //添付ファイル削除
                var indexList = new List <Attachment>();
                foreach (var attachment in mail.Attachments.Cast <Attachment>())
                {
                    indexList.Add(attachment);
                }
                indexList.ForEach(i =>
                {
                    i.Delete();
                });
                mail.BodyFormat = OlBodyFormat.olFormatPlain;

                mail.Body = string.Join("\r\n", listList) + "------------------------------------------\r\n" + mail.Body;
                mail.Display();
            }
        }
Example #5
0
        public void copyMailItem()
        {
            //MessageBox.Show("Juhu");

            //            Outlook.MailItem mail = this.Application.GetNamespace("MAPI").
            Outlook.MailItem mail = toOtrs_2020.Application.GetNamespace("MAPI").
                                    GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).
                                    Items.GetFirst() as Outlook.MailItem;


            //Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)this.Application.
            Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)toOtrs_2020.Application.
                                       ActiveExplorer().Session.GetDefaultFolder
                                           (Outlook.OlDefaultFolders.olFolderInbox);
            // Outlook.Items items = (Outlook.Items)inBox.Items;
            //Object selObject = this.Application.ActiveExplorer().Selection[1];
            Object selObject = toOtrs_2020.Application.ActiveExplorer().Selection[1];

            Outlook.MailItem selectedMail = (selObject as Outlook.MailItem);

            //Outlook.MailItem moveMail = null;
            //items.Restrict("[UnRead] = true");

            //Outlook.MAPIFolder destFolder = inBox.Folders["Test"];

            // Dialog zum TicketID erfassen anzeigen.
            Objparam.Subject = selectedMail.Subject;
            getTicketID _getTicketID = new getTicketID(Objparam);

            _getTicketID.ShowDialog();

            // Outlook.MAPIFolder destFolder = this.Application.Session.PickFolder() as Outlook.Folder;

            //Outlook.MAPIFolder destFolder = DestFolder();
            string _folderID = getDestFolder();

            if (_folderID != null)
            {
                //                Outlook.MAPIFolder destFolder = (Outlook.MAPIFolder)this.Application.ActiveExplorer().Session.GetFolderFromID(_folderID);
                Outlook.MAPIFolder destFolder = (Outlook.MAPIFolder)toOtrs_2020.Application.ActiveExplorer().Session.GetFolderFromID(_folderID);



                if (selectedMail != null && Objparam.IsChecked != false)
                {
                    // Create a copy of the item.
                    Outlook.MailItem copyMail = selectedMail.Copy() as Outlook.MailItem;

                    // Objparam.NewSubject wurde in getTicketID() ermittelt.
                    //copyMail.Subject = Objparam.NewSubject;

                    string MailTime = selectedMail.ReceivedTime.ToString();

                    copyMail.Subject = Objparam.Subject + " - " + MailTime;

                    // kopierte Mail verschieben.
                    try
                    {
                        copyMail.Move(destFolder);
                    }
                    catch
                    {
                        MessageBox.Show("Zielordner nicht gefunden. Bitte Registry Key löschen und Pfad neu setzen.\n HKEY_CURRENT_USER\\SOFTWARE\\BDG\\ToOTRS");
                    }
                }
            }
        }
Example #6
0
        private void AfterSendUnsafe(object Item)
        {
            if (!CurrentSettings.AddInEnabled || CurrentSettings.OutgoingFirstAction == OutgoingFirstAction.DoNothing)
            {
                return;
            }

            Outlook.MailItem mailItem = Item as Outlook.MailItem;

            var domains = new HashSet <string>();

            foreach (Outlook.Recipient recipient in mailItem.Recipients)
            {
                string recipientAddress;
                if (!TryGetRecipientAddress(recipient, out recipientAddress))
                {
                    continue;
                }

                string domain;
                if (!TryGetDomain(recipientAddress, out domain))
                {
                    continue;
                }

                if (!domains.Contains(domain))
                {
                    domains.Add(domain);
                }
            }

            var domainsAllowed = domains.Except(CurrentSettings.OutgoingExceptions);

            Outlook.Rules ruleSet   = null;
            var           needsSave = false;

            if (domainsAllowed.Count() > 0 && CurrentSettings.OutgoingFirstAction == OutgoingFirstAction.CreateSentFolderRule)
            {
                RefreshRules();
                ruleSet = RuleSet;
            }

            foreach (var domain in domainsAllowed)
            {
                var ruleName   = OutgoingRulePrefix + domain;
                var initChar   = char.ToUpper(domain.Take(1).First());
                var folderName = SentboxFolderNamePrefix + initChar.ToString() + domain.Substring(1);

                Outlook.MAPIFolder parentFolder = null;
                if (CurrentSettings.OutgoingCreateParentFolders)
                {
                    var parentFolderName = GetParentFolderName(initChar);
                    if (!TryGetFolder(parentFolderName, Sentbox, out parentFolder))
                    {
                        parentFolder = CreateFolder(parentFolderName, Sentbox);
                    }
                }
                else
                {
                    parentFolder = Sentbox;
                }

                Outlook.MAPIFolder folder = null;
                if (!TryGetFolder(folderName, parentFolder, out folder))
                {
                    folder = CreateFolder(folderName, parentFolder);
                }

                try
                {
                    var copy = mailItem.Copy() as Outlook.MailItem;
                    copy.Move(folder);
                }
                catch
                {
                    // tried to move if it does not happen ignore
                }

                if (CurrentSettings.OutgoingFirstAction == OutgoingFirstAction.CreateSentFolderRule)
                {
                    if (!RuleExists(ruleSet, ruleName))
                    {
                        CreateOutgoingRule(ruleSet, ruleName, domain, folder, mailItem);
                        needsSave = true;
                    }
                }
            }

            if (needsSave && ruleSet != null)
            {
                ruleSet.Save(false);
            }
        }
        public void OnConvertButton(Office.IRibbonControl control)
        {
            StagingTicket ticket = new StagingTicket();

            Outlook.Application application = new Outlook.Application();
            Outlook.NameSpace   ns          = application.GetNamespace("MAPI");

            //get selected outlook object / mail item
            Object selectedObject = application.ActiveExplorer().Selection[1];

            Outlook.MailItem selectedMail = (Outlook.MailItem)selectedObject;

            //in case a email object si selected run the workflow
            if (selectedObject != null)
            {
                //1. invoke web service
                try
                {
                    //instanciate service and invoke it create the ticket and to receive the ticket reference (ID)
                    Remedy2OutlookService service = new Remedy2OutlookService();
                    ticket = service.invoke(selectedMail);
                }
                catch (Exception ex)
                {
                    string path = AppDomain.CurrentDomain.BaseDirectory + @"\temp";
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(path + @"\errors.log", true))
                    {
                        file.WriteLine(DateTime.Now.ToString() + " - " + ex.Message + "\n" + ex.ToString());
                    }

                    // display an error message
                    MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }


                //2. open submitted ticket in browser or display info/warn/error messages
                if (Properties.Settings.Default.OpenInBrowser && ticket.wid != null)
                {
                    dynamic ie  = Activator.CreateInstance(Type.GetTypeFromProgID("InternetExplorer.Application"));
                    string  url = Properties.Settings.Default.AppConsoleURL;

                    if (url.EndsWith("/"))
                    {
                        url.Remove(url.Length - 1);
                    }
                    if (url.IndexOf("?", 0) > 0)
                    {
                        url += "&eid=" + ticket.wid;
                    }
                    else
                    {
                        url += "?eid=" + ticket.wid;
                    }

                    ie.AddressBar = false;
                    ie.MenuBar    = false;
                    ie.ToolBar    = false;
                    ie.Visible    = true;
                    ie.Navigate2(url);
                }
                else
                {
                    if (ticket.wid != null && String.Equals(ticket.sts, "done"))
                    {
                        MessageBox.Show("Remedy workflow ticket has been created: " + ticket.wid, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (ticket.rid != null && String.Equals(ticket.sts, "open"))
                    {
                        MessageBox.Show("Selected email is transferred to Remedy into the staging record [" + ticket.rid + "] but the fulfillment ticket was not created due to an error or misconfiguration.\n\nContact your Administrator!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (String.Equals(ticket.sts, "error") && ticket.log != null)
                    {
                        MessageBox.Show("Remedy workflow error: " + ticket.log + ".\n\nContact your Administrator!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }


                //3. mark selected email as read
                if (Properties.Settings.Default.ReadMail && ticket.wid != null)
                {
                    selectedMail.UnRead = false;
                    selectedMail.Save();
                }


                //4. insert reference ticket number in the
                if (Properties.Settings.Default.InsertInSubject && ticket.wid != null)
                {
                    selectedMail.Subject = ticket.wid + ": " + selectedMail.Subject;
                    selectedMail.Save();
                }

                //5. copy selected email item into Backup MAPI folder (if not exist will be created)
                if (Properties.Settings.Default.BackupMail && ticket.wid != null)
                {
                    Outlook.Folder     inbox  = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) as Outlook.Folder;
                    Outlook.MAPIFolder backup = null;

                    foreach (Outlook.MAPIFolder subfolder in inbox.Folders)
                    {
                        if (String.Equals(subfolder.Name, "Backup"))
                        {
                            backup = subfolder;
                            break;
                        }
                    }

                    if (backup == null)
                    {
                        try
                        {
                            backup = inbox.Folders.Add("Backup", Outlook.OlDefaultFolders.olFolderInbox);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error trying to create Backup MAPI folder: " + ex.Message + ".\n\nContact your Administrator or create it manually!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }

                    if (backup != null)
                    {
                        Outlook.MailItem copyMail = selectedMail.Copy();
                        copyMail.Move(backup);
                    }

                    if (inbox != null)
                    {
                        Marshal.ReleaseComObject(inbox);
                    }
                    if (backup != null)
                    {
                        Marshal.ReleaseComObject(backup);
                    }
                }

                //6. delete selected email item
                if (Properties.Settings.Default.RemoveMail && ticket.wid != null)
                {
                    selectedMail.Delete();
                }
            }
        }