private void CreateCustomFolder(Outlook.OlDefaultFolders parentFolder, string folderName) { Outlook.Folder folder = (Outlook.Folder) Application.ActiveExplorer().Session.GetDefaultFolder (parentFolder); Outlook.Folder customFolder = null; try { customFolder = (Outlook.Folder)folder.Folders.Add(folderName, Outlook.OlDefaultFolders.olFolderInbox); customFolder.WebViewURL = "http://www.google.com"; customFolder.WebViewOn = true; //folder.Folders[folderName].Display(); } catch (Exception ex) { } }
public static Outlook.Items GetOutlookItems(Outlook.OlDefaultFolders outlookDefaultFolder, string syncFolder) { Outlook.MAPIFolder mapiFolder = null; if (string.IsNullOrEmpty(syncFolder)) { mapiFolder = OutlookNameSpace.GetDefaultFolder(outlookDefaultFolder); if (mapiFolder == null) { throw new Exception("Error getting Default OutlookFolder: " + outlookDefaultFolder); } } else { mapiFolder = OutlookNameSpace.GetFolderFromID(syncFolder); if (mapiFolder == null) { throw new Exception("Error getting OutlookFolder: " + syncFolder); } } try { Outlook.Items items = mapiFolder.Items; if (items == null) { throw new Exception("Error getting Outlook items from OutlookFolder: " + mapiFolder.Name); } else { return(items); } } finally { if (mapiFolder != null) { Marshal.ReleaseComObject(mapiFolder); mapiFolder = null; } } }
private static Outlook.Items SearchMailsInConversationInFolder(Outlook.MailItem mail, Outlook.OlDefaultFolders folderType) { //http://www.outlookcode.com/codedetail.aspx?id=1714 var folder = Globals.GreatFollowUpperAddin.Application.Session.GetDefaultFolder(folderType); var parsedConversationTopic = mail.ConversationTopic?.Replace("\"", "\"\"").Replace("'", "''"); // " If the search string contains a single quote character, escape the single quote character in the string with another single quote character." >> https://msdn.microsoft.com/en-us/library/office/aa210275%28v=office.11%29.aspx?f=255&MSPPError=-2147217396 var topic = "[ConversationTopic] = " + "\"" + parsedConversationTopic + "\""; return(folder.Items.Restrict(topic)); }
public static int SaveMailAttach(string folder_path, Outlook.OlDefaultFolders opt) { try { // Create the Outlook application. // in-line initialization Outlook.Application oApp = new Outlook.Application(); // Get the MAPI namespace. Outlook.NameSpace oNS = oApp.GetNamespace("mapi"); // Log on by using the default profile or existing session (no dialog box). oNS.Logon(Missing.Value, Missing.Value, false, true); // Alternate logon method that uses a specific profile name. // TODO: If you use this logon method, specify the correct profile name // and comment the previous Logon line. //oNS.Logon("profilename",Missing.Value,false,true); //Get the Inbox folder. Outlook.MAPIFolder oInbox = oNS.GetDefaultFolder(opt); //Get the Items collection in the Inbox folder. Outlook.Items oItems = oInbox.Items; foreach (var item in oItems) { Outlook.MailItem msg = item as Outlook.MailItem; if (msg == null) { continue; } for (int i = 1; i <= msg .Attachments.Count; i++) { try { msg.Attachments[i].SaveAsFile (folder_path + msg.Attachments[i].FileName); } //Error handler. catch (Exception e) { Console.WriteLine("{0} Exception caught: ", e); } } } oNS.Logoff(); oItems = null; oInbox = null; oNS = null; oApp = null; } //Error handler. catch (Exception e) { Console.WriteLine("{0} Exception caught: ", e); } return(0); }
public Outlook.MAPIFolder this[Outlook.OlDefaultFolders FolderType] { get { return(GetFolder(FolderType)); } }
private Outlook.MAPIFolder GetFolder(Outlook.OlDefaultFolders FolderType) { return(Space.GetDefaultFolder(FolderType)); }