//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
} // 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."); } }
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 }
//private void BtnLogin_Click(object sender, HtmlElementEventArgs e) //{ // switch (e.MouseButtonsPressed) // { // case MouseButtons.Left: // HtmlElement element = webBrowserLogin.Document.GetElementFromPoint(e.ClientMousePosition); // if (element != null && "submit".Equals(element.GetAttribute("type"), StringComparison.OrdinalIgnoreCase)) // { // HtmlElement logId = webBrowserLogin.Document.GetElementById("username"); // } // break; // } //} private string getLoggedInUser() { string LoggedinUserID = String.Empty; Microsoft.Office.Interop.Outlook.Recipient item = Globals.ThisAddIn.Application.ActiveExplorer().Session.CurrentUser; if (item.AddressEntry.Type == "SMTP") { LoggedinUserID = item.AddressEntry.Address; } //If the User is Exchange type then extraction of Email ID is different. else if (item.AddressEntry.Type == "EX") { Microsoft.Office.Interop.Outlook.AddressEntry rec = item.AddressEntry; string psmtp = item.AddressEntry.GetExchangeUser().PrimarySmtpAddress; if (psmtp != null) { LoggedinUserID = psmtp; } else { //Emailid if not fetched from above method trying to fetch it using MAPI property. //System.Windows.Forms.MessageBox.Show("PrimarySMTPAddress Property of exchange returned null.Trying with MAPI properties now."); try { item.Resolve(); string PR_SMTP_ADDRESS = @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E"; string email = ""; email = rec.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS).ToString(); if (email != "") { LoggedinUserID = email; } } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show("Failed to get Email via MAPI, " + ex.Message); } } } return(LoggedinUserID); }
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(); }
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; } }
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  "; oMsg.HTMLBody += "quantity  "; 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 }
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 }