예제 #1
0
 public Attachment(Microsoft.Office.Interop.Outlook.Attachment Attachment)
 {
     _Attachment = Attachment;
     Class       = Attachment.Class.ToString();
     DisplayName = Attachment.DisplayName;
     FileName    = Attachment.FileName;
     Index       = Attachment.Index;
     Size        = Attachment.Size;
 }
예제 #2
0
        /// <summary>
        /// Takes an Outlook email object and searches the Attachment field
        /// </summary>
        /// <param name="email_obj">Microsoft.Office.Interop.Outlook.MailItem object</param>
        /// <param name="query">String to search for in Attached file names</param>
        /// <returns>True/False on Found/Not found</returns>
        protected bool Search_Attachment_Name(_MI_ email_obj, string query)
        {
            System.Collections.IEnumerator enumer = null;
            enumer = email_obj.Attachments.GetEnumerator();
            while (enumer.MoveNext())
            {
                Microsoft.Office.Interop.Outlook.Attachment temp = null;
                temp = (Microsoft.Office.Interop.Outlook.Attachment)enumer.Current;
                if (temp.FileName.ToLower().Contains(query.ToLower()))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #3
0
        }       // enviar email

        private void email_Click(object sender, EventArgs e)
        {
            try
            {
                Microsoft.Office.Interop.Outlook.Application oApp      = new Microsoft.Office.Interop.Outlook.Application();
                Microsoft.Office.Interop.Outlook._MailItem   oMailItem = (Microsoft.Office.Interop.Outlook._MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
                oMailItem.To = "meter campo transportadora.email";

                oMailItem.HTMLBody = "Segue em anexo o pdf com os dados da encomenda. <br> Atentamente, AMD";

                //Add an attachment.
                String sDisplayName = "Encomenda";
                int    iPosition    = (int)oMailItem.Body.Length + 1;
                int    iAttachType  = (int)Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue;

                //now attached the file
                Microsoft.Office.Interop.Outlook.Attachment oAttach = oMailItem.Attachments.Add(@"C:\\fileName.jpg", iAttachType, iPosition, sDisplayName);

                //Subject line
                oMailItem.Subject = "Encomenda AMD";

                // Add a recipient.
                Microsoft.Office.Interop.Outlook.Recipients oRecips = (Microsoft.Office.Interop.Outlook.Recipients)oMailItem.Recipients;

                // Change the recipient in the next line if necessary.
                Microsoft.Office.Interop.Outlook.Recipient oRecip = (Microsoft.Office.Interop.Outlook.Recipient)oRecips.Add("meter o campo da transportadora.email");
                oRecip.Resolve();

                oMailItem.Display(true);

                // Send.
                oMailItem.Send();

                // Clean up.
                oRecip    = null;
                oRecips   = null;
                oMailItem = null;
                oApp      = null;
            }


            catch (Exception ex)
            {
                MessageBox.Show("Não conseguimos carregar a aplicação de email. Por favor tente mais tarde.");
            }
        }
예제 #4
0
        private void SendMessage(Microsoft.Office.Interop.Outlook.Application oApp, List <string> bodyMessage, string stringBodyMessage, string receiver, string subject, string from, string to)
        {
            try
            {
                // Create a new mail item. Pass the application received on the form as parameter
                Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

                //add the body of the email
                oMsg.HTMLBody = stringBodyMessage;
                //Add an attachment.
                String sDisplayName = "MyAttachment";
                int    iPosition    = (int)oMsg.Body.Length + 1;
                int    iAttachType  = (int)Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue;
                //now attached the file
                prepareMessage(bodyMessage, from, to);
                //clearFieldsAndClose();

                string thePath = Path.Combine
                                     (AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "picture1.png");
                Microsoft.Office.Interop.Outlook.Attachment oAttach =
                    oMsg.Attachments.Add(thePath, iAttachType, iPosition, sDisplayName);

                //Subject line
                oMsg.Subject = subject;
                // Add a recipient.
                Microsoft.Office.Interop.Outlook.Recipients oRecips =
                    (Microsoft.Office.Interop.Outlook.Recipients)oMsg.Recipients;
                // Change the recipient in the next line if necessary.
                Microsoft.Office.Interop.Outlook.Recipient oRecip =
                    (Microsoft.Office.Interop.Outlook.Recipient)oRecips.Add(receiver);
                oRecip.Resolve();
                // Send.
                oMsg.Send();
                // Clean up.
                oRecip  = null;
                oRecips = null;
                oMsg    = null;
                oApp    = null;
            }//end of try block
            catch (System.Exception ex)
            {
                MessageBox.Show("An error occurs. " + ex.Message);
            }//end of catch
        }
예제 #5
0
파일: SendEmail.cs 프로젝트: flarelli/uteis
        public static void EnviarEmail(int qntCenario, int qntCenarioSucesso, double percentagemTestes)
        {
            var dateTime   = DateTime.Now.ToString("dd-MM-yyyy");
            var reportPath = AppDomain.CurrentDomain.BaseDirectory.Replace("bin\\Debug\\", "Report");

            DirectoryInfo info = new DirectoryInfo(reportPath + "\\" + dateTime);

            FileInfo[] files = info.GetFiles().OrderBy(p => p.CreationTime).ToArray();

            int totalArquivos = files.Count() - 1;

            var arquivo = reportPath + "\\" + dateTime + "\\" + files[totalArquivos].ToString();


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

            Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

            oMsg.HTMLBody = "Relatório de Automação de Testes Mesa Originação" + "<pre>" + "</pre>" + "Ambiente de QA";


            //Adiciona Texto no corpo do e-mail
            String attach = "Attachment to add to the Mail";
            int    x      = (int)oMsg.Body.Length + 1;
            int    y      = (int)Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue;


            //Anexa os arquivos aqui
            Microsoft.Office.Interop.Outlook.Attachment oAttach = oMsg.Attachments.Add(arquivo, y, x, attach);
            //Adiciona Assunto no e-mail
            oMsg.Subject = percentagemTestes + "% - " + qntCenarioSucesso + "/" + qntCenario + " scripts " + dateTime;

            //Informa o e-mail destinatário
            Microsoft.Office.Interop.Outlook.Recipients oRecips = (Microsoft.Office.Interop.Outlook.Recipients)oMsg.Recipients;

            Microsoft.Office.Interop.Outlook.Recipient oRecip = (Microsoft.Office.Interop.Outlook.Recipient)oRecips.Add("email");
            oRecip.Resolve();



            //Envia o e-mail
            oMsg.Send();
        }
        public void SendanEmail()
        {
            Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();

            Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

            oMsg.HTMLBody = "Selenium Webdriver Test Execution Report";
            //Add an attachment.
            String attach = "Attachment to add to the Mail";
            int    x      = (int)oMsg.Body.Length + 1;
            int    y      = (int)Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue;

            //Attach the file here
            Microsoft.Office.Interop.Outlook.Attachment oAttach = oMsg.Attachments.Add(@"c:\sagar\reports.html", y, x, attach);
            //here you can add the Subject of mail item
            oMsg.Subject = "Automation Reports of Test Execution";
            // Here you can Add the mail id to which you want to send mail.
            Microsoft.Office.Interop.Outlook.Recipients oRecips = (Microsoft.Office.Interop.Outlook.Recipients)oMsg.Recipients;

            Microsoft.Office.Interop.Outlook.Recipient oRecip = (Microsoft.Office.Interop.Outlook.Recipient)oRecips.Add("*****@*****.**");
            oRecip.Resolve();
        }
        public static string GetFileName(this Microsoft.Office.Interop.Outlook.Attachment source)
        {
            var result = "<hidden>" + source.Index;

            try
            {
                result = source.FileName;
            }
            catch
            {
                try
                {
                    result = source.DisplayName;
                }
                catch
                {
                    //TODO: log exception
                }
            }

            return(result);
        }
예제 #8
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.");
            }
        }