//method to send email to outlook
        private static void sendEMailThroughOUTLOOK(MailCommand mailCommand)
        {
            try
            {
                // Create the Outlook application.
                Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
                // Create a new mail item.
                Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
                // Set HTMLBody.
                //add the body of the email
                if (mailCommand.Exception != null)
                {
                    oMsg.HTMLBody = "Error !!!" + Environment.NewLine + Environment.NewLine + mailCommand.Exception.Message;
                }
                else if (mailCommand.CommandType == CommandType.Exit | mailCommand.CommandType == CommandType.Hi | mailCommand.CommandType == CommandType.Stop | mailCommand.CommandType == CommandType.Start)
                {
                    oMsg.HTMLBody = mailCommand.Description;
                }
                else
                {
                    oMsg.HTMLBody = ConvertToHtmlFile(mailCommand);
                }

                //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
                //Outlook.Attachment oAttach = oMsg.Attachments.Add(@"C:\\fileName.jpg", iAttachType, iPosition, sDisplayName);
                //Subject line
                oMsg.Subject = mailCommand.Command + " Executed (" + DateTime.Now.ToLongTimeString() + ")";
                // 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(mailCommand.ToAddress);
                oRecip.Resolve();
                // Send.
                oMsg.Send();
                // Clean up.
                oRecip  = null;
                oRecips = null;
                oMsg    = null;
                oApp    = null;

                Logger.Log(mailCommand.Command + " Result Send To " + mailCommand.ToAddress);
            }//end of try block
            catch (Exception ex)
            {
                Logger.Log(ex.Message);
            } //end of catch
        }     //end of Email Method
예제 #2
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.");
            }
        }
예제 #3
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
        }
예제 #4
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();
        }
예제 #6
0
 private void CreateMail(string Subject, string htmlBody, DataTable dtEmail)
 {
     try
     {
         this.Cursor = Cursors.WaitCursor;
         Microsoft.Office.Interop.Outlook.Application app      = new Microsoft.Office.Interop.Outlook.Application();
         Microsoft.Office.Interop.Outlook.MailItem    mailItem = (Microsoft.Office.Interop.Outlook.MailItem)app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
         mailItem.Subject = Subject;
         Microsoft.Office.Interop.Outlook.Recipients oRecips = (Microsoft.Office.Interop.Outlook.Recipients)mailItem.Recipients;
         Microsoft.Office.Interop.Outlook.Recipient  oRecip  = (Microsoft.Office.Interop.Outlook.Recipient)oRecips.Add("*****@*****.**");
         oRecip.Resolve();
         oRecips             = null;
         mailItem.BCC        = "*****@*****.**";
         mailItem.HTMLBody   = htmlBody;
         mailItem.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh;
         mailItem.Send();
         this.Cursor = Cursors.Default;
     }
     catch
     {
         this.Cursor = Cursors.Default;
     }
 }
예제 #7
0
        void Sendmail(String s)
        {
            try
            {
                // Create the Outlook application.
                Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
                // Create a new mail item.
                Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
                // Set HTMLBody.
                //add the body of the email
                //oMsg.HTMLBody = null;
                oMsg.HTMLBody += "Item Name &emsp;";
                oMsg.HTMLBody += "quantity &emsp;";
                oMsg.HTMLBody += "Price <br />";

                oMsg.HTMLBody += s;

                //Subject line
                oMsg.Subject = "Order Details";
                // 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 = oRecips.Add("*****@*****.**");
                oRecip.Resolve();
                // Send.
                oMsg.Send();
                // Clean up.
                oRecip  = null;
                oRecips = null;
                oMsg    = null;
                oApp    = null;
            }//end of try block
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }//end of catch
        }
예제 #8
0
        private void button1_Click(object sender, EventArgs e)
        {
            Console.WriteLine("Satep1\n");
            BillDAO          billDAOImpl = new BillDAOImpl();
            OrderCredentials o           = new OrderCredentials();

            o.billNo = billNo;
            Bill billref = new Bill();

            billref.billNoRef = o;
            Console.WriteLine("Step22");
            List <ArrayList> listBill = billDAOImpl.getBillList(billref);

            for (int i = 0; i < listBill.Count; i++)
            {
                Console.WriteLine("Step 3 inside for Loop\t");
                billref.orderId = Convert.ToInt32(listBill[i][0]);
                billDAOImpl.deleteBill(billref);
            }
            Console.WriteLine("step 4");
            OrderCredentialsDAO ordercRedDAORef = new OrderCredentialsDAOImpl();

            Console.WriteLine("Step5");
            ordercRedDAORef.deleteorderCredentials(o);
            MessageBox.Show("Order cancelled !!");
            canecelOrderBtn.Visible = false;


            try
            {
                // Create the Outlook application.
                Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();

                // Create a new mail item.
                Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

                // Set HTMLBody.
                //add the body of the email
                //oMsg.HTMLBody = null;


                oMsg.HTMLBody = "Order got cancelled!!!!";


                //Subject line
                oMsg.Subject = "Order Details";
                // 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 = oRecips.Add("*****@*****.**");
                oRecip.Resolve();
                // Send.
                oMsg.Send();
                // Clean up.
                oRecip  = null;
                oRecips = null;
                oMsg    = null;
                oApp    = null;
            }//end of try block
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }//end of catch
        }
예제 #9
0
        public void CreateNewDistributionList(string[] tabAdresse)
        {
            Microsoft.Office.Interop.Outlook._Application OutlookApp       = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.NameSpace    ns               = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder   folderContacts   = null;
            Microsoft.Office.Interop.Outlook.Items        contactItems     = null;
            Microsoft.Office.Interop.Outlook.MailItem     mail             = null;
            Microsoft.Office.Interop.Outlook.Recipients   listRecipients   = null;
            Microsoft.Office.Interop.Outlook.DistListItem distributionList = null;
            try
            {
                string addresseToAdd;
                ns             = OutlookApp.GetNamespace("MAPI");
                folderContacts = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts);
                contactItems   = folderContacts.Items;
                // create a new e-mail message to access the recipients collection
                mail           = contactItems.Add(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem) as Microsoft.Office.Interop.Outlook.MailItem;
                mail.To        = "";
                listRecipients = mail.Recipients;
                //création de la liste d'adresse
                foreach (string addresse in tabAdresse)
                {
                    if (addresse != null)
                    {
                        addresseToAdd = RemoveDiacritics(addresse);
                        listRecipients.Add(addresseToAdd);
                    }
                }

                if (!listRecipients.ResolveAll())
                {
                    System.Windows.Forms.MessageBox.Show("There are no such contact names. " +
                                                         "Please make sure that you have corresponding records in your address book",
                                                         "Add-in Express", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                // create a new distribution list item
                distributionList = contactItems.Add(Microsoft.Office.Interop.Outlook.OlItemType.olDistributionListItem)
                                   as Microsoft.Office.Interop.Outlook.DistListItem;
                distributionList.DLName = "List judo";
                distributionList.AddMembers(listRecipients);
                distributionList.Display(true);
            }
            catch (Exception e)
            {
                throw new Exception("Erreur Metier.cs/CreateNewDistributionList():\r\n" + e.Message, e);
            }
            finally
            {
                if (distributionList != null)
                {
                    Marshal.ReleaseComObject(distributionList);
                }
                if (listRecipients != null)
                {
                    Marshal.ReleaseComObject(listRecipients);
                }
                if (mail != null)
                {
                    mail.Delete();
                    Marshal.ReleaseComObject(mail);
                }
                if (contactItems != null)
                {
                    Marshal.ReleaseComObject(contactItems);
                }
                if (folderContacts != null)
                {
                    Marshal.ReleaseComObject(folderContacts);
                }
                if (ns != null)
                {
                    Marshal.ReleaseComObject(ns);
                }
            }
        }