public WHSMailService() { // get an instance of the MAPI namespace and login Outlook.Application app = new Outlook.ApplicationClass(); _nameSpace = app.GetNamespace("MAPI"); _nameSpace.Logon(null, null, false, false); }
private void ThisApplication_NewMail(string EntryIDCollection) { Outlook.ApplicationClass outLookApp = new Outlook.ApplicationClass(); NameSpace outLookNS = outLookApp.GetNamespace("MAPI"); MAPIFolder outLookFolder = outLookNS.GetDefaultFolder(OlDefaultFolders.olFolderInbox); string storeID = outLookFolder.StoreID; MailItem newEmail = (MailItem)outLookNS.GetItemFromID(EntryIDCollection, storeID); ThisApplication_OperateDataByEmail(newEmail); }
private Microsoft.Office.Interop.Outlook.Items GetBaseContacts() { try { Microsoft.Office.Interop.Outlook.NameSpace ns = OutlookApplication.GetNamespace("MAPI"); Microsoft.Office.Interop.Outlook.MAPIFolder contactsFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts); Microsoft.Office.Interop.Outlook.Items contactItems = contactsFolder.Items; return(contactItems); } catch (System.Exception ex) { FireContactManagerFailureEvent(ex); return(null); } }
public static void ReadOutlook() { Outlook._Application olApp = new Outlook.ApplicationClass(); Outlook._NameSpace olNS = olApp.GetNamespace("MAPI"); olNS.Logon("@OutlookEmail", "@OutlookPassword", false, false); Outlook.MAPIFolder oFolder = olNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); TodayDate = DateTime.Now.ToString("MM/dd/yyyy"); Outlook.Items oItems = oFolder.Items.Restrict("[ReceivedTime] >= '" + TodayDate + "'"); //Outlook.Items oItems = oFolder.Items.Restrict("[UnRead] = true"); for (int i = 1; i <= oItems.Count; i++) { Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oItems[i]; MailSubject = oMsg.Subject.ToString(); MailBody = System.Web.HttpUtility.JavaScriptStringEncode(oMsg.Body); if (MailSubject.StartsWith("RE:") || MailSubject.StartsWith("FW:") || MailSubject.StartsWith("Re:") || MailSubject.StartsWith("Fw:") || MailSubject.StartsWith("Fwd:")) { // Do not fetch mail with contains word above (reply and forward type) } else { EmailCount++; NewEmailList.Add(MailSubject); Console.WriteLine(MailSubject + MailBody); CreatJiraIssue(MailSubject, MailBody); } } ListName = string.Join("\n", NewEmailList.ToArray()); Console.WriteLine(EmailCount); Microsoft.Office.Interop.Outlook.MailItem oMsgSend = (Outlook.MailItem)olApp.CreateItem(Outlook.OlItemType.olMailItem); oMsgSend.To = "######Recieved_Email######"; oMsgSend.To = "######Sender_Email######"; oMsgSend.Subject = "Summary Auto Email Fetching " + TodayDate; oMsgSend.Body = "All New Email count: " + EmailCount + "\n\nFetching complete: " + EmailCount + "\n\nList Email names: \n\n" + ListName; oMsgSend.Save(); oMsgSend.Send(); }
public static void ReadOutlookNightCrawler() { //I think ApplicationClass() works only if you have outlook installed Outlook.Application outlook = new Outlook.ApplicationClass(); Outlook.NameSpace ns = outlook.GetNamespace("Mapi"); object _missing = Type.Missing; ns.Logon(_missing, _missing, false, true); //Outlook.MAPIFolder inbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); Outlook.Recipient recip = (Outlook.Recipient)ns.CreateRecipient("*****@*****.**"); Outlook.MAPIFolder inbox = ns.GetSharedDefaultFolder(recip, Outlook.OlDefaultFolders.olFolderInbox); int unread = inbox.UnReadItemCount; /* foreach (Outlook.MailItem mail in inbox.Items) { string s = mail.Subject; } */ Outlook.MailItem mitem = inbox.Items[1] as Outlook.MailItem; //mitem.PrintOut(); string AttachmentFolder = System.AppDomain.CurrentDomain.BaseDirectory + @"Attachments"; if (!Directory.Exists(AttachmentFolder)) { Directory.CreateDirectory(AttachmentFolder); } mitem.Attachments[1].SaveAsFile(System.AppDomain.CurrentDomain.BaseDirectory + "a"); }
private void HooksNewMail() { string pos = "ThisAddIn.HooksNewMail - "; log.Info(pos + "INIT"); Outlook.Application app = new Outlook.ApplicationClass(); _NameSpace ns = app.GetNamespace("MAPI"); ns.Logon(null, null, false, false); log.Info(pos + "Inizio hooking delle folder"); Outlook.Folders collectionFolders = ns.Folders; for (int i = 1; i <= collectionFolders.Count; i++) { if (collectionFolders[i].Store.DisplayName.ToLower().EndsWith(Constants.KP_DOMAIN.ToLower())) { log.Info(pos + "Hook della root:" + collectionFolders[i].Name); Outlook.Folder rootFolder = (Outlook.Folder)collectionFolders[i]; Outlook.Folders collectionRootFolders = rootFolder.Folders; for (int j = 1; j <= collectionRootFolders.Count; j++) { Outlook.Folder childFolder = (Outlook.Folder)collectionRootFolders[j]; log.Info(pos + "Hook della cartella:" + childFolder.Name); listItems.Add(childFolder.Items); listItems[j - 1].ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(FlagKpeopleMail); } } } log.Info(pos + "END"); }
private void buttonGetOutlookList_Click(object sender, EventArgs e) { bool _homeFax = false; bool _businessFax = false; string _homeFaxNumber = string.Empty; string _businessFaxNumber = string.Empty; Cursor.Current = Cursors.WaitCursor; try { Outlook.Application objOutlookTest = null; Outlook.NameSpace objNamespaceTest = null; Outlook.MAPIFolder objFolderTest = null; objOutlookTest = new Outlook.ApplicationClass(); objNamespaceTest = objOutlookTest.GetNamespace("MAPI"); objFolderTest = objNamespaceTest.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); int _count = objFolderTest.Items.Count; } catch (Exception er) { MessageBox.Show("Error getting Address book entries", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Common.Log(er.Message); Cursor.Current = Cursors.Default; return; } Outlook.Application objOutlook = null; Outlook.NameSpace objNamespace = null; Outlook.MAPIFolder objFolder = null; Outlook.ContactItem item = null; try { objOutlook = new Outlook.ApplicationClass(); objNamespace = objOutlook.GetNamespace("MAPI"); objFolder = objNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); Debug.WriteLine(objFolder.Items.Count + " Contacts found."); } catch (System.Exception ex) { Cursor.Current = Cursors.Default; Debug.WriteLine(ex.Message); } gridOutlookList.RowCount = 0; gridOutlookList.ColCount = 4; gridOutlookList.ColWidths[0] = 10; gridOutlookList.RowHeights[0] = 35; gridOutlookList.ColWidths[1] = 200; gridOutlookList.ColWidths[2] = 150; gridOutlookList.ColWidths[3] = 150; gridOutlookList.ColWidths[4] = 0; gridOutlookList[0, 1].Text = "Name"; gridOutlookList[0, 2].Text = "Business Fax"; gridOutlookList[0, 3].Text = "Home Fax"; gridOutlookList[0, 1].BackColor = Color.LightGray; gridOutlookList[0, 2].BackColor = Color.LightGray; gridOutlookList[0, 3].BackColor = Color.LightGray; gridOutlookList[0, 4].BackColor = Color.LightGray; objFolder.Items.Sort("LastNameAndFirstName", false); //gridOutlookList.RowCount = objFolder.Items.Count; for (int i = 1; i < objFolder.Items.Count + 1; i++) { try { _homeFax = false; _businessFax = false; //string _homeFaxNumber = string.Empty; //string _businessFaxNumber = string.Empty; try { item = (Outlook.ContactItem)objFolder.Items[i]; } catch { } try { //gridOutlookList[i, 4].Text = item.BusinessFaxNumber; _businessFaxNumber = item.BusinessFaxNumber; if (_businessFaxNumber.Length > 0) { _businessFax = true; } } catch { } try { //gridOutlookList[i, 5].Text = item.HomeFaxNumber; _homeFaxNumber = item.HomeFaxNumber; if (_homeFaxNumber.Length > 0) { _homeFax = true; } } catch { } if (_businessFax || _homeFax ) { gridOutlookList.RowCount = gridOutlookList.RowCount + 1; try { gridOutlookList[gridOutlookList.RowCount, 1].Text = item.LastNameAndFirstName; gridOutlookList[gridOutlookList.RowCount, 1].Enabled = false; } catch { } try { if (item.BusinessFaxNumber.Length > 0) { gridOutlookList[gridOutlookList.RowCount, 2].Description = item.BusinessFaxNumber; gridOutlookList[gridOutlookList.RowCount, 2].CellType = "PushButton"; gridOutlookList[gridOutlookList.RowCount, 2].CellAppearance = Syncfusion.Windows.Forms.Grid.GridCellAppearance.Raised; } } catch { } try { if (item.HomeFaxNumber.Length > 0) { gridOutlookList[gridOutlookList.RowCount, 3].Description = item.HomeFaxNumber; gridOutlookList[gridOutlookList.RowCount, 3].CellType = "PushButton"; gridOutlookList[gridOutlookList.RowCount, 3].CellAppearance = Syncfusion.Windows.Forms.Grid.GridCellAppearance.Raised; } } catch { } } } catch { } } SortCol(1, gridOutlookList); gridOutlookList[0, 1].CellAppearance = GridCellAppearance.Raised; Cursor.Current = Cursors.Default; }