private MailItem ReplyAll(MailItem mail, string content)
        {
            try
            {
                var reply = mail.ReplyAll();
                switch (reply.BodyFormat)
                {
                //case OlBodyFormat.olFormatPlain:
                //    reply.Body = GetTemplate(mail.SenderName, content) + reply.Body;
                //    break;

                case OlBodyFormat.olFormatHTML:
                    reply.HTMLBody = GetTemplateHTML(mail.SenderName, content) + reply.HTMLBody;
                    break;

                //case OlBodyFormat.olFormatRichText:
                //    reply.HTMLBody = GetTemplateHTML(mail.SenderName, content) + reply.HTMLBody;
                //    break;

                default:
                    reply.Body = GetTemplate(mail.SenderName, content) + reply.Body;
                    break;
                }
                reply.SentOnBehalfOfName = helpdesk;
                return(reply);
            }
            finally
            {
                ReleaseCom(mail);
            }
        }
        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();
                }
            }
        }
Exemple #3
0
        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");
            }
        }
Exemple #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);
                        }
                    }
                }
            }
        }
Exemple #5
0
        private void BtnGerarOrdem_Click(object sender, EventArgs e)
        {
            //Valida se possui boletas
            if (DataGridBoletas.Rows.Count == 0)
            {
                MessageBox.Show("Nenhuma boleta no DataGrid!"); return;
            }

            string IDORDEM = new BL_Ordem().Inserir(LabelEmail.Text, LabelAssunto.Text);

            foreach (DataGridViewRow DR in DataGridBoletas.Rows)
            {
                new BL_Boleta().Inserir(IDORDEM, Convert.ToInt64(DR.Cells[0].Value), Convert.ToInt64(DR.Cells[1].Value), DR.Cells[6].Value.ToString(), Convert.ToDateTime(DR.Cells[9].Value),
                                        Convert.ToDateTime(DR.Cells[10].Value), DR.Cells[5].Value.ToString(), Convert.ToDecimal(DR.Cells[7].Value), DR.Cells[8].Value.ToString(), Convert.ToInt64(DR.Cells[11].Value));
            }

            DataGridBoletas.Rows.Clear();

            //Criar Email de Recebimento.
            string HTML = new HTML().ConfirmaRecebimento(new BL_Boleta().DadosIDORDEM(IDORDEM));

            MailItem EmailReply = EmailRecebido.ReplyAll();

            EmailReply.Recipients.Add("*****@*****.**");
            EmailReply.HTMLBody = "<HTML><BODY>" + HTML + "</BODY></HTML>" + EmailReply.HTMLBody;
            if (CheckRecebimento.Checked)
            {
                EmailReply.Send();
            }
            else
            {
                EmailReply.Display();
            }

            Microsoft.Office.Interop.Outlook.Application outlook = new Microsoft.Office.Interop.Outlook.Application();
            NameSpace  nameSpace            = outlook.GetNamespace("MAPI");
            MAPIFolder mapiFolderPurchase   = nameSpace.GetDefaultFolder(OlDefaultFolders.olFolderInbox).Parent;
            MAPIFolder BoletadosFolder      = mapiFolderPurchase.Folders["Boletas do Dia"];
            MAPIFolder BoletadosRecebimento = mapiFolderPurchase.Folders["Boletas Recebidas"];

            //EmailRecebido.Move(BoletadosFolder);
            //EmailReply.Move(BoletadosRecebimento);

            MessageBox.Show("Ordem Gerada!");
        }
        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);
            }
        }
Exemple #8
0
        async void CreateIssue()
        {
            CreatingIssue = true;
            try
            {
                var createdIssue = await new CreateIssuesApi(githubApi.Context).CreateIssue(SelectedRepository, IssueTitle, IssueDescription);
                currentMailItem.UserProperties.SetPropertyValue("GitHubIssueId", OlUserPropertyType.olNumber, createdIssue.Id, false);
                var reply = currentMailItem.ReplyAll();
                reply.Body = string.Format("I have created an issue at {0} to track this issue.\r\n\r\nThanks for reporting it.",
                                           createdIssue.HtmlUrl);
                reply.Display(Modal: false);

                OnClose();
            }
            finally
            {
                CreatingIssue = false;
            }
        }
Exemple #9
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);
                }
            }
        }