Ejemplo n.º 1
0
        /**
         *
         * This method will permanently delete an email from Outlook, similar to
         * the use of the shift+delete manually on an email in Outlook.
         * Surprise, surprise...Microsoft does not have a method to easily
         * perform a PERMANENT DELETE of an email...you literally have to move
         * the phish eMail to the Deleted Items folder first, and then delete it
         * from there.  This is the only way, at least since the writing of this
         * comment, that we can permanently delete an email out of Outlook in
         * Visual C#
         *
         */
        private void permanentlyDeleteEmail(
            Microsoft.Office.Interop.Outlook.MailItem currMail)
        {
            Microsoft.Office.Interop.Outlook.Explorer currExplorer =
                Globals.ThisAddIn.Application.ActiveExplorer();

            Microsoft.Office.Interop.Outlook.Store store =
                currExplorer.CurrentFolder.Store;

            Microsoft.Office.Interop.Outlook.MAPIFolder deletedItemsFolder =
                store.GetRootFolder().Folders[DELETED_ITEMS_FOLDER_NAME];

            // The move here will retain a reference to the MailItem entity that
            // is moved to the Deleted items folder...this is good because we
            // don't need to search for this email in Deleted Items...thank the
            // Maker!
            Microsoft.Office.Interop.Outlook.MailItem movedMail =
                currMail.Move(deletedItemsFolder);

            // Stupid Microsoft action here...need to change a value to trigger a
            // Save...otherwise, upcoming Delete will NOT OCCUR!!!!
            movedMail.Subject = movedMail.Subject + " ";

            // Need to save it...
            movedMail.Save();

            // Now, permanently delete it!
            movedMail.Delete();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creation des mail outlook
        /// </summary>
        /// <param name="chemin_pdf"></param>
        /// <param name="adresse_mail"></param>
        /// <param name="textBox_sujet_mail"></param>
        /// <param name="textBox_message_mail"></param>
        public static void CreateMailOutlookAvecPJ(string chemin_pdf, string adresse_mail, string textBox_sujet_mail, string textBox_message_mail)
        {
            StringBuilder msgBuilder = new StringBuilder();

            Microsoft.Office.Interop.Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application();

            Microsoft.Office.Interop.Outlook.MailItem mail = (Microsoft.Office.Interop.Outlook.MailItem)outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

            mail.Subject  = textBox_sujet_mail;
            mail.To       = adresse_mail;
            mail.HTMLBody = textBox_message_mail;

            mail.Attachments.Add(chemin_pdf);
            mail.Save();

            // mail.Display(true);

            //        Outlook.NameSpace omNamespace = outlookApp.GetNamespace("MAPI");
            //        Outlook.Recipient omUser = omNamespace.CreateRecipient("test");
            //        omUser.Resolve();
            //        Outlook.MAPIFolder doissierBrouillon = omNamespace.GetSharedDefaultFolder(omUser, Outlook.OlDefaultFolders.olFolderDrafts)
            // Dim omMailItem As Outlook.MailItem = CType(omDrafts.Items.Add, Outlook.MailItem)
            // With omMailItem
            //    .SentOnBehalfOfName = "*****@*****.**"
            //    .To = "*****@*****.**"
            //    .Subject = "Test"
            //    .Body = "Test email"
            //    .Save()
            //    .Move(omDrafts)
        }
Ejemplo n.º 3
0
        private void bt_ok_Click(object sender, EventArgs e)
        {
            this.Hide();
            // réécriture du fichier de destinations précedentes
            if (!lines.Contains(tb_destination.Text))
            {
                string[] newlines = new string[lines.Length + 1];
                newlines[0] = tb_destination.Text;
                Array.ConstrainedCopy(lines, 0, newlines, 1, lines.Length);
                File.WriteAllLines(filename, newlines);
            }

            archiver = new Archiver(this.tb_destination.Text, this);
            if (this.cb_explode_attachements.Checked)
            {
                archiver.EnableExtractAttachments();
            }
            if (Config.GetInstance().GetOption("TRUNCATE_PATH_TOO_LONG").Equals("TRUE"))
            {
                archiver.EnableTruncatePathTooLong();
            }
            if (Config.GetInstance().GetOption("ASK_PATH_TOO_LONG").Equals("TRUE"))
            {
                archiver.EnableAskPathTooLong();
            }
            string res = archiver.ArchiveItem(mailitem,
                                              this.tb_destination.Text,
                                              this.TB_RENAME.Text);

            if (res == "Ok")
            {
                var customCat = Localisation.getInstance().getString(
                    culture.TwoLetterISOLanguageName,
                    "ARCHIVED_CATEGORY"
                    );
                if (mailitem.Categories == null || mailitem.Categories.Trim().Equals("")) // no current categories assigned
                {
                    mailitem.Categories = customCat;
                }
                else if (!mailitem.Categories.Contains(customCat)) // insert as first assigned category
                {
                    mailitem.Categories = string.Format("{0}, {1}", customCat, mailitem.Categories);
                }

                mailitem.Save();
            }
            MessageBox.Show(res);
            this.Dispose();
        }
Ejemplo n.º 4
0
        void snapControl1_Letter_DocumentLoaded(object sender, DevExpress.Snap.DocumentImportedEventArgs e)
        {
            BeginInvoke(new MethodInvoker(delegate {
                memoEdit1.Text += String.Format("Letter: {0}, was sent to {1}\r\n", lettersCache[CurrentEmailIndex].ContentFileName, lettersCache[CurrentEmailIndex].CustomerEMail);

                Microsoft.Office.Interop.Outlook.Application application = new Microsoft.Office.Interop.Outlook.Application();
                Microsoft.Office.Interop.Outlook.MailItem mailItem       = (Microsoft.Office.Interop.Outlook.MailItem)application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

                mailItem.To      = lettersCache[CurrentEmailIndex].CustomerEMail;
                mailItem.Subject = lettersCache[CurrentEmailIndex].EMailSubject;

                RichEditMailMessageExporter exporter = new RichEditMailMessageExporter(snapControl1, mailItem);
                exporter.Export();

                mailItem.Save();


                CurrentEmailIndex++;
                SendCurrentLetter(CurrentEmailIndex);
            }));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Saves an email object of type Microsoft.Office.Interop.Outlook.MailItem to Drafts Box
        /// </summary>
        /// <param name="new_message">Microsoft.Office.Interop.Outlook.MailItem object</param>
        /// <returns>True/False on Success/Failure</returns>
        protected bool Save_to_Draftbox(_MI_ new_message)
        {
            Microsoft.Office.Interop.Outlook.Application app       = null;
            Microsoft.Office.Interop.Outlook._NameSpace  nameSpace = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder  drafts    = null;
            try
            {
                app       = new Microsoft.Office.Interop.Outlook.Application();
                nameSpace = app.GetNamespace("MAPI");
                nameSpace.Logon(null, null, false, false);

                drafts = nameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderDrafts);
                new_message.Save();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(false);
            }

            return(true);
        }
Ejemplo n.º 6
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.");
            }
        }
Ejemplo n.º 7
0
        protected override void Execute(CodeActivityContext context)
        {
            Microsoft.Office.Interop.Outlook.Application outlookApplication = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.MailItem    email = (Microsoft.Office.Interop.Outlook.MailItem)outlookApplication.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

            var    to       = To.Get(context);
            var    cc       = CC.Get(context);
            var    bcc      = BCC.Get(context);
            var    subject  = Subject.Get(context);
            var    account  = Account.Get(context);
            string body     = (Body != null ?Body.Get(context) : null);
            string htmlbody = (HTMLBody != null ? HTMLBody.Get(context) : null);

            if (!string.IsNullOrEmpty(htmlbody))
            {
                body = htmlbody;
            }
            var attachments = Attachments.Get(context);
            var uiaction    = UIAction.Get(context);

            Microsoft.Office.Interop.Outlook.Account oAccount = null;
            if (!string.IsNullOrEmpty(account))
            {
                for (int i = 1; i <= outlookApplication.Session.Accounts.Count; i++)
                {
                    if (outlookApplication.Session.Accounts[i].SmtpAddress == account)
                    {
                        oAccount = outlookApplication.Session.Accounts[i];
                    }
                }
            }

            email.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatRichText;
            if (oAccount != null)
            {
                email.SendUsingAccount = oAccount;
            }
            email.To       = to;
            email.Subject  = subject;
            email.HTMLBody = body;
            email.CC       = cc;
            email.BCC      = bcc;

            if (attachments != null && attachments.Count() > 0)
            {
                foreach (var attachment in attachments)
                {
                    if (!string.IsNullOrEmpty(attachment))
                    {
                        email.Attachments.Add(attachment, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, 100000, Type.Missing);
                    }
                }
            }
            if (uiaction == "Show")
            {
                email.Display(true);
            }
            //else if(uiaction == "SendVisable")
            //{
            //    email.Display(true);
            //    email.Send();
            //}
            if (uiaction == "Draft")
            {
                email.Save();
            }
            else
            {
                email.Send();
            }
            if (EMail != null)
            {
                EMail.Set(context, new email(email));
            }
        }
        private void button1_Click(object sender, RibbonControlEventArgs e)
        {
            // Process to receive active selection and save email files only
            Microsoft.Office.Interop.Outlook.Inspector currInspector = null;
            Microsoft.Office.Interop.Outlook.Explorer  currExplorer  = null;
            Microsoft.Office.Interop.Outlook.MailItem  currMail      = null;

            log.Debug("User selected button to SendSecure!");

            try
            {
                currExplorer  = Globals.ThisAddIn.Application.ActiveExplorer();
                currInspector = Globals.ThisAddIn.Application.ActiveInspector();

                log.Debug("Verifying we are in a Mail Editor...");

                // We are in the Mail Editor...
                if (currInspector.CurrentItem is Microsoft.Office.Interop.Outlook.MailItem)
                {
                    currMail = (Microsoft.Office.Interop.Outlook.MailItem)currInspector.CurrentItem;

                    // There are cases where the user may be in the Subject area
                    // and edited, and they did not tab our save the email.  In
                    // those cases, the current mail's subject would not be
                    // updated accordingly.  In order to get around that, we
                    // need to save the current email and then pull the subject.
                    currMail.Save();

                    if (currMail.Subject != null)
                    {
                        // Check if the send secure literal already exists prepended on
                        // the subject...if todes...don't prepend another literal!!!
                        string currMailSubject = currMail.Subject.ToUpper();

                        log.Debug("Secure Email Subject: " + currMailSubject);

                        string secureSendLiteral =
                            Properties.Settings.Default.secureEmailSendLiteral;

                        if (currMailSubject.StartsWith(
                                secureSendLiteral.ToUpper()) == false)
                        {
                            string subject = secureSendLiteral + currMail.Subject;

                            log.Debug(
                                "Prepending send secure literal to subject: " +
                                subject);

                            currMail.Subject = subject;
                        }
                        else
                        {
                            if (Properties.Settings.Default.addInDebug == true)
                            {
                                string message =
                                    "Secure Literal already exists!  Skipping step to prepend...";

                                MessageBox.Show(message);

                                log.Debug(message);
                            }
                        }
                    }

                    // Add check for property to send email out after the button is
                    // clicked...
                    if (Properties.Settings.Default.secureEmailSendEmailOnButtonClick == true)
                    {
                        bool sendEmail = true;

                        log.Debug("Sending Email due to Send Secure Button click...");

                        if (Properties.Settings.Default.secureEmailSendConfirmation == true)
                        {
                            // Display the confirmation form to the user...
                            var result = sendConfirmationForm.ShowDialog();

                            if (result != DialogResult.Yes)
                            {
                                log.Debug("User has opted to NOT send the secure email!");

                                sendEmail = false;
                            }
                        }

                        if (sendEmail == true)
                        {
                            log.Debug("Sending secure email...");

                            currMail.Send();
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 9
0
        private void SendMain_Click(object sender, RoutedEventArgs e)
        {
            //получить текст из richtextbox
            string newText = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text;

            if (telFlag)
            {
                using (StreamReader sw = new StreamReader("namechanell.txt"))
                {
                    nameCanal = sw.ReadLine();
                }
                //отправляем в телеграм
                //861879980:AAHlhxjh6YncToyBNjtSM45cF9YZeqiSdD4
                botClient = new TelegramBotClient(tokenTelegram);
                //botClient.SendPhotoAsync("@diejdkekr", photoHeaderDispData);
                try
                {
                    FileStream fstream = System.IO.File.OpenRead(way);

                    Telegram.Bot.Types.InputFiles.InputOnlineFile t = new Telegram.Bot.Types.InputFiles.InputOnlineFile(fstream, TxtFile.Text);
                    //https://t.me/voronenokhse
                    botClient.SendPhotoAsync(nameCanal, t, newText);
                    flag = true;
                }
                catch (System.ArgumentNullException)
                {
                    string url = "https://api.telegram.org/bot" + tokenTelegram + "/sendMessage";

                    using (var webClient = new WebClient())
                    {
                        // Создаём коллекцию параметров
                        var pars = new NameValueCollection();

                        // Добавляем необходимые параметры в виде пар ключ, значение
                        pars.Add("text", newText);
                        pars.Add("chat_id", nameCanal);
                        // Посылаем параметры на сервер
                        // Может быть ответ в виде массива байт
                        try
                        {
                            var response = webClient.UploadValues(url, pars);
                            flag = true;
                        }
                        catch (Exception ex)
                        {
                            System.Windows.MessageBox.Show("Нельзя отправить полностью пустое сообщение\n" + ex.Message);
                        }
                    }
                }
                catch
                {
                    System.Windows.MessageBox.Show("ошибка");
                }
            }

            if (vkFlag)
            {
                //try
                //{
                //отправляем в ВК
                try
                {
                    var    VkClass = new vkWallPost("ae363f8388210268830659859871e929f4ceb3976839d856b8aedf8d7ce812b1bd9100ede063380ab1070");
                    string result  = VkClass.AddWallPost(-180723519, newText, TxtFile.Text, time, data);
                    System.Windows.Forms.MessageBox.Show(result);

                    //"""в это время уже было отправлено"" сделать месседжбокс
                    string ch          = "for this time";
                    int    indexOfChar = result.IndexOf(ch);
                    if (result == "Error")
                    {
                        throw (new Exception("Нельзя отправлять полностью пустое сообщение"));
                    }
                    flag = true;
                }
                catch (System.Net.WebException)
                {
                    System.Windows.MessageBox.Show("Нет подключения к сети");
                }

                //}
                //catch (Exception ex)
                //{
                //    System.Windows.MessageBox.Show(ex.Message);
                //}
            }
            //отправка в OutLook
            string listOfPost = "";

            if (outFlag || OutSave || OutSend)
            {
                //try{
                Microsoft.Office.Interop.Outlook._Application _app = new Microsoft.Office.Interop.Outlook.Application();
                Microsoft.Office.Interop.Outlook.MailItem     mail = (Microsoft.Office.Interop.Outlook.MailItem)_app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
                using (StreamReader sw = new StreamReader("OutLookTxt.txt"))
                {
                    string s = sw.ReadLine();
                    while (s != "" && s != null)
                    {
                        listOfPost += s + ";";
                        s           = sw.ReadLine();
                    }
                }
                listOfPost = listOfPost.Substring(0, listOfPost.Length - 1);
                mail.To    = listOfPost;
                using (StreamReader sw = new StreamReader("themaTxt.txt"))
                {
                    string s = sw.ReadLine();
                    mail.Subject = s;
                }
                mail.Body       = newText;
                mail.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceNormal;
                try
                {
                    mail.Attachments.Add(TxtFile.Text, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, 1, "Няяяяяяя");
                }
                catch (DirectoryNotFoundException) { }

                //}
                //catch (Exception ex)
                //{
                //    System.Windows.MessageBox.Show(ex.Message, "Ошибка");
                //}
                flag = true;
                if (OutSave)
                {
                    mail.Save();
                }
                else
                {
                    mail.Send();
                }
            }
            if (rgNew)
            {
                string titlerg;
                using (StreamReader sw = new StreamReader("titleRgNews.txt"))
                {
                    titlerg = sw.ReadLine();
                }

                var options = new ChromeOptions();
                options.AddArguments("headless");
                using (IWebDriver driver = new ChromeDriver(options))
                {
                    driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(60);
                    driver.Navigate().GoToUrl("https://www.researchgate.net/project/TestPro/update/create");
                    driver.FindElement(By.Id("input-login")).SendKeys("*****@*****.**");
                    //System.Threading.Thread.Sleep(500);
                    driver.FindElement(By.Id("input-password")).SendKeys("fynbakee1");
                    driver.FindElement(By.CssSelector("button.nova-c-button")).Click();
                    driver.FindElement(By.Id("field-title")).SendKeys(titlerg);
                    driver.FindElement(By.CssSelector("div.converse-editor__input")).Click();
                    Actions action = new Actions(driver);
                    action.SendKeys(newText).Build().Perform();
                    driver.FindElement(By.CssSelector("button.nova-c-button[type='submit']")).Click();
                    rgNew = false;
                }
                if (rgAnons)
                {
                    rgAnons = false;
                }
                if (flag)
                {
                    MessSaveBox objModal = new MessSaveBox();
                    objModal.Owner = this;
                    ApplyEffect(this);
                    objModal.ShowDialog();
                    ClearEffect(this);
                }
            }
        }
Ejemplo n.º 10
0
        private void btnLoadMessages_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Outlook.Application myApp         = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.NameSpace   mapiNameSpace = myApp.GetNamespace("MAPI");

            KeyValuePair <string, string> selectedItem = (KeyValuePair <string, string>)cmbOutlookFolders.SelectedItem;

            Microsoft.Office.Interop.Outlook.MailItem mail01 = myApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem) as Microsoft.Office.Interop.Outlook.MailItem;
            Microsoft.Office.Interop.Outlook.MailItem mail02 = myApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem) as Microsoft.Office.Interop.Outlook.MailItem;

            mail01.Subject = "Move Deliverable Between TOWs Errors";
            mail01.Body    = "Hello Laura," + Environment.NewLine + Environment.NewLine +
                             "Attached are this week’s emails." + Environment.NewLine + Environment.NewLine +
                             "Thanks, Keith";

            mail02.Subject = "WorkOrders with No Deliverable";
            mail02.Body    = "Hello Laura," + Environment.NewLine + Environment.NewLine +
                             "Attached are this week’s emails." + Environment.NewLine + Environment.NewLine +
                             "Thanks, Keith";

            Microsoft.Office.Interop.Outlook.AddressEntry currentUser = myApp.Session.CurrentUser.AddressEntry;
            Microsoft.Office.Interop.Outlook.ExchangeUser manager     = currentUser.GetExchangeUser().GetExchangeUserManager();
            // Add recipient using display name, alias, or smtp address
            //mail.Recipients.Add(manager.PrimarySmtpAddress);
            mail01.Recipients.ResolveAll();
            mail02.Recipients.ResolveAll();

            Microsoft.Office.Interop.Outlook.MAPIFolder myInbox = mapiNameSpace.GetFolderFromID(selectedItem.Key);
            //cmbOutlookFolders.SelectedItem.ToString());// GetDefaultFolder(Microsoft.Office.Interop.Outlook.O.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
            int total = myInbox.Items.Count, count = 0, xytCount = 0, unread = 0;

            if (total > 0)
            {
                foreach (Microsoft.Office.Interop.Outlook.MailItem item in myInbox.Items)
                {
                    count++;
                    unread++;
                    ListViewItem listitem = new ListViewItem(new[]
                    {
                        item.ReceivedTime.ToString(), item.SenderEmailAddress + "(" + item.Sender.Address.ToString() + ")", item.Subject, ((item.Attachments.Count > 0) ? "Yes" : "No"), item.EntryID.ToString()
                    });

                    if (item.Body.Contains("Attempt to move a Deliverable between TOWs"))
                    {
                        listitem.BackColor = Color.Plum;
                        xytCount++;

                        mail01.Attachments.Add(item, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
                    }

                    if (item.Body.Contains("Failure Message Deliverable with Id"))
                    {
                        listitem.BackColor = Color.GreenYellow;
                        xytCount++;

                        mail02.Attachments.Add(item, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
                    }

                    lstMsg.Items.Add(listitem);
                }

                lblEmailCount.Text = string.Format("Total Emails: {0}, Emails Need Attention: {1}, Unread: {2} ", total, xytCount, unread);
            }

            mail01.Save();
            mail02.Save();
        }