public override void RunCommand(object sender) { var vRecipients = v_Recipients.ConvertToUserVariable(sender); var vAttachment = v_Attachment.ConvertToUserVariable(sender); var vSubject = v_Subject.ConvertToUserVariable(sender); var vBody = v_Body.ConvertToUserVariable(sender); var vBodyType = v_BodyType.ConvertToUserVariable(sender); var splittext = vRecipients.Split(';'); 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); Microsoft.Office.Interop.Outlook.AddressEntry currentUser = outlookApp.Session.CurrentUser.AddressEntry; if (currentUser.Type == "EX") { Microsoft.Office.Interop.Outlook.ExchangeUser manager = currentUser.GetExchangeUser().GetExchangeUserManager(); // Add recipient using display name, alias, or smtp address foreach (var t in splittext) { mail.Recipients.Add(t.ToString()); } mail.Recipients.ResolveAll(); mail.Subject = vSubject; if (vBodyType == "HTML") { mail.HTMLBody = vBody; } else { mail.Body = vBody; } if (!string.IsNullOrEmpty(vAttachment)) { mail.Attachments.Add(vAttachment); } mail.Send(); } }
//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 Form1(Microsoft.Office.Interop.Outlook.AddressEntry entry) { InitializeComponent(); this.Load += new EventHandler(Form1_Load); this.mEntry = entry; }
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(); }
private string buildPhishingEmailBody(Microsoft.Office.Interop.Outlook.MailItem mail) { string phishingEmailBody = ""; // Get MAIL HEADER information... // Envelope Sender // Reply-To // From // Sender IP // Sender Domain string senderEmailAddress = null; string senderName = null; // The following value is semi-colon delimited... string replyRecipients = mail.ReplyRecipientNames; if (mail != null) { // Need to handle EXCHANGE versus SMTP email types. If the // SenderEmailType is NULL, it is netiher an EXCHANGE or SMTP // originaed email. In this case, it may be auto-generated by // a bot...in this case, just share the SenderName if available. if (mail.SenderEmailAddress == null) { senderEmailAddress = mail.SenderEmailAddress; senderName = mail.SenderName; } else if (mail.SenderEmailType.ToLower() == "ex") { Microsoft.Office.Interop.Outlook.AddressEntry sender = mail.Sender; Microsoft.Office.Interop.Outlook.ExchangeUser exUser = sender.GetExchangeUser(); senderEmailAddress = exUser.PrimarySmtpAddress; senderName = mail.SenderName; } else if (mail.SenderEmailType.ToLower() == "smtp") { senderEmailAddress = mail.SenderEmailAddress; senderName = mail.SenderName; } log.Debug( "Metadata for Phishing Email Body:\n" + "Sender Name: " + senderName + "\n" + "Sender Email Address: " + senderEmailAddress + "\n" + "Reply-To: " + replyRecipients + "\n"); Microsoft.Office.Interop.Outlook.PropertyAccessor outlookPA = mail.PropertyAccessor; const string TRANSPORT_MESSAGE_HEADERS_PROPERTY = "http://schemas.microsoft.com/mapi/proptag/0x007D001E"; string mailHeaders = outlookPA.GetProperty(TRANSPORT_MESSAGE_HEADERS_PROPERTY); phishingEmailBody = "From: " + senderName; if (senderEmailAddress != null) { phishingEmailBody += " <" + senderEmailAddress + ">\n"; } else { phishingEmailBody += "\n"; } phishingEmailBody += "Reply-To: " + replyRecipients + "\n" + "Headers:\n" + mailHeaders; } return(phishingEmailBody); }