예제 #1
0
        public static void ReplyTo(MailMessage message, string body, List <string> attachments, bool replyAll, CancellationToken ct)
        {
            Application application = null;
            MailItem    mailItem    = null;
            MailItem    mailItem2   = null;

            ct.ThrowIfCancellationRequested();
            application = InitOutlook();
            using (application.DisposeWithReleaseComObject())
            {
                NameSpace @namespace = application.GetNamespace("MAPI");
                string    text       = message.Headers["Uid"];
                if (string.IsNullOrEmpty(text))
                {
                    throw new ArgumentException("非法的邮件对象!");
                }
                mailItem = (dynamic)@namespace.GetItemFromID(text, Type.Missing);
                using (mailItem.DisposeWithReleaseComObject())
                {
                    mailItem2 = (replyAll ? mailItem.ReplyAll() : mailItem.Reply());
                }
                using (mailItem2.DisposeWithReleaseComObject())
                {
                    foreach (string attachment in attachments)
                    {
                        ct.ThrowIfCancellationRequested();
                        mailItem2.Attachments.Add(attachment, Type.Missing, Type.Missing, Type.Missing);
                    }
                    mailItem2.HTMLBody   = body + mailItem2.HTMLBody;
                    mailItem2.BodyFormat = OlBodyFormat.olFormatHTML;
                    ct.ThrowIfCancellationRequested();
                    mailItem2.Send();
                }
            }
        }
예제 #2
0
        public static MailItem OpenReply(this Application outlook, MailItem mail)
        {
            var replyMail = mail.Reply();
            var inspector = (Inspector)outlook.Inspectors.Add(replyMail);

            inspector.Activate();
            return(replyMail);
        }
 public MailItem Reply(MailItem mail)
 {
     if (mail != null)
     {
         return(mail.Reply());
     }
     else
     {
         throw new NullReferenceException("Mail cannot be null.");
     }
 }
예제 #4
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 vBody         = v_Body.ConvertToUserVariable(sender);
            var vAttachment   = v_Attachment.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];
                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 == "Reply")
                        {
                            MailItem newMail = tempMail.Reply();
                            Reply(newMail, vBody, vAttachment);
                        }
                        else if (v_OperationType == "Reply All")
                        {
                            MailItem newMail = tempMail.ReplyAll();
                            Reply(newMail, vBody, vAttachment);
                        }
                    }
                }
            }
        }
        public override void RunCommand(object sender)
        {
            var      engine      = (AutomationEngineInstance)sender;
            MailItem vMailItem   = (MailItem)v_MailItem.ConvertUserVariableToObject(engine);
            var      vBody       = v_Body.ConvertUserVariableToString(engine);
            var      vAttachment = v_Attachments.ConvertUserVariableToString(engine);

            if (v_OperationType == "Reply")
            {
                MailItem newMail = vMailItem.Reply();
                Reply(newMail, vBody, vAttachment);
            }
            else if (v_OperationType == "Reply All")
            {
                MailItem newMail = vMailItem.ReplyAll();
                Reply(newMail, vBody, vAttachment);
            }
        }
        public async override Task RunCommand(object sender)
        {
            var      engine    = (IAutomationEngineInstance)sender;
            MailItem vMailItem = (MailItem)await v_MailItem.EvaluateCode(engine);

            var vBody = (string)await v_Body.EvaluateCode(engine);

            if (v_OperationType == "Reply")
            {
                MailItem newMail = vMailItem.Reply();
                await Reply(engine, newMail, vBody);
            }
            else if (v_OperationType == "Reply All")
            {
                MailItem newMail = vMailItem.ReplyAll();
                await Reply(engine, newMail, vBody);
            }
        }
예제 #7
0
파일: Main.cs 프로젝트: EBERSHR/FormPlugin
        public static void automaticReply(MailItem email)
        {
            if (!checkIfTemplateWasSend)
            {
                //ORANGE CATEGORY
                //oznaczCalaKonwersacjeKategoria(email, "You Must Decide");
                ///////////////
                /*MessageBox.Show("Musisz wysłać dopiero template.");*/
            }
            else if (checkIfFitToTemplate)
            {
                //GREEN CATEGORY
                oznaczCalaKonwersacjeKategoria(email, "Good Response");
                ////////////

                /*MessageBox.Show("NIE ODSYŁAMY bo zgadza się template :)" +
                 *  "\nTemplateWasSend: " + checkIfTemplateWasSend +
                 *  "\nTemplateFilled: " + checkIfFitToTemplate);*/
            }
            else if (!checkIfFitToTemplate && checkIfTemplateWasSend)
            {
                /////////////
                /*MessageBox.Show("ODSYŁAMY automatycznie bo chamy niemyte nie czytajoXD");*/
                DialogResult result = MessageBox.Show("Do you want to send template once again? \n" + email.Subject + ",\n" + Tools.ShowAllReceivers(), "Confirmation", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    Outlook.Application oApp         = new Outlook.Application();
                    MailItem            emailToReply = oApp.CreateItemFromTemplate(pathForTemplate) as MailItem;
                    emailToReply.Subject = "RE: " + email.Subject;
                    emailToReply.To      = email.ReplyAll().To;
                    if (email != null)
                    {
                        Outlook.MailItem replyMail = email.Reply();
                        replyMail.HTMLBody = emailToReply.HTMLBody + replyMail.HTMLBody;
                        replyMail.To       = email.ReplyAll().To;
                        replyMail.Send();
                    }
                }
                //RED CATEGORY
                oznaczCalaKonwersacjeKategoria(email, "Bad Response");
            }
        }
예제 #8
0
        public static void ReplyDu(this Application outlook, MailItem mail)
        {
            var replyMail = mail.Reply();

            if (mail.Sender.TryGetGreetingName(out var greetingName))
            {
                replyMail.Body = String.Format(@"Hallo {0},



Freundliche Grüße,

Andreas
", greetingName) + replyMail.Body;
            }

            var inspector = (Inspector)outlook.Inspectors.Add(replyMail);

            inspector.Activate();
        }
예제 #9
0
        public void PerformAction(string speechText)
        {
            speechText = Utility.TruncateActionString(speechText, "Reply");

            var item = Utility.GetNThItem(speechText);

            if (item is MailItem)
            {
                MailItem mailItem  = (MailItem)item;
                MailItem replyItem = mailItem.Reply();

                Globals.ThisAddIn.Application.ActiveExplorer().ClearSelection();
                replyItem.Display(false);

                VoiceSearch.speakItOut(" The Subject of the mail is : " + replyItem.Subject + ", You are Replying to " + replyItem.To).GetAwaiter().GetResult();
                //Task.Delay(1000).Wait();
                VoiceSearch.speakItOut("Tell me what you want to reply.").GetAwaiter().GetResult();
                //Task.Delay(2000).Wait();
                string body = VoiceSearch.RecognizeSpeechAsync().GetAwaiter().GetResult();
                replyItem.Body = body;

                VoiceSearch.speakItOut("Your Reply is ready. Do you want to Send or Discard?").GetAwaiter().GetResult();
                //Task.Delay(2000).Wait();

                string action = VoiceSearch.RecognizeSpeechAsync().GetAwaiter().GetResult();
                if (action.ToLower().Contains("send"))
                {
                    replyItem.Send();
                    VoiceSearch.speakItOut("Mail Sent.").GetAwaiter().GetResult();
                }
                else
                {
                    replyItem.Close(OlInspectorClose.olDiscard);
                    VoiceSearch.speakItOut("Mail Discarded.").GetAwaiter().GetResult();
                }
            }
            else
            {
                Console.WriteLine(item.GetType());
            }
        }
예제 #10
0
        private void replyAndKeepAttachments(object sender, RibbonControlEventArgs e)
        {
            // Get the inspector
            Inspector inspector = e.Control.Context as Inspector;
            // Get the current mail message
            MailItem mailItem = inspector.CurrentItem as MailItem;

            // Check if we have a mail message to work with
            if (mailItem != null)
            {
                // Check if we have attachments
                if (mailItem.Attachments.Count > 0)
                {
                    // Variable holding the reply
                    MailItem mailItemToSend;

                    // Check if Reply All button was pressed
                    if (replyAll)
                    {
                        // Create the reply all message item
                        mailItemToSend = mailItem.ReplyAll();
                    }
                    else
                    {
                        // Create the reply message item
                        mailItemToSend = mailItem.Reply();
                    }

                    // Iterate through each attachment
                    foreach (Attachment attachment in mailItem.Attachments)
                    {
                        try
                        {
                            string PR_ATTACH_FLAGS = "http://schemas.microsoft.com/mapi/proptag/0x37140003";
                            // Get property of attachment (ATT_INVISIBLE_IN_HTML | ATT_INVISIBLE_IN_RTF)
                            var attachmentFlags = attachment.PropertyAccessor.GetProperty(PR_ATTACH_FLAGS);
                            // If attachment is not ATT_MHTML_REF
                            if (attachmentFlags != 4)
                            {
                                // Path of the folder to save files before attaching
                                string folderPath = @"C:\ReplyKeepAttachmentsTmp";
                                try
                                {
                                    // Check if the folder does not exist
                                    if (!Directory.Exists(folderPath))
                                    {
                                        // Create the folder if it doesn't exist
                                        DirectoryInfo directoryInfo = Directory.CreateDirectory(folderPath);
                                    }

                                    // Check if the attachment is not an embeeded element
                                    if ((int)attachment.Type != 6)
                                    {
                                        // Save current attachment
                                        attachment.SaveAsFile(Path.Combine(@"C:\ReplyKeepAttachmentsTmp\", attachment.FileName));
                                        if (mailItemToSend != null)
                                        {
                                            // Attach it to the reply message
                                            mailItemToSend.Attachments.Add(Path.Combine(@"C:\ReplyKeepAttachmentsTmp\", attachment.FileName));
                                            //mailItemToSend.Save();
                                            // Delete the temporary file
                                            if (File.Exists(Path.Combine(@"C:\ReplyKeepAttachmentsTmp\", attachment.FileName)))
                                            {
                                                File.Delete(Path.Combine(@"C:\ReplyKeepAttachmentsTmp\", attachment.FileName));
                                            }
                                        }
                                    }
                                }
                                catch (System.IO.IOException ioException)
                                {
                                    // Show a message showing that there was an error while attempting to create the temporary folder
                                    MessageBox.Show("There was an error while attempting to create the temporary folder to save attachments:\n\n" +
                                                    ioException.Message, "Reply and Keep Attachments Add-In Message", MessageBoxButton.OK, MessageBoxImage.Error);
                                }
                                catch (System.Exception genericException)
                                {
                                    // Show the exception message
                                    MessageBox.Show(genericException.Message, "Reply and Keep Attachments Add-In Message", MessageBoxButton.OK, MessageBoxImage.Error);
                                }
                                finally { }
                            }
                        }
                        catch (System.Runtime.InteropServices.COMException comException)
                        {
                            MessageBox.Show(comException.Message, "Reply and Keep Attachments Add-In Message", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    // Check if the message to send is valid
                    if (mailItemToSend != null)
                    {
                        // Open the reply Window to allow the user to edit and send the message
                        mailItemToSend.GetInspector.Activate();
                    }
                }
                else
                {
                    // Show a message saying that no attachments could be found
                    MessageBox.Show("No attachments could be found on this mail message.", "Reply and Keep Attachments Add-In Message", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
            }
        }