working on it ...

Filters

Explore Public Snippets

Sort by

Found 2 snippets matching: ".net outlook api"

    public by sherazam  182346  1  5  0

    How to Delete Messages in Bulk or One by One from Outlook PST in .NET Apps

    This technical tip explains how .NET developers can Delete Messages from outlook PST. Add Messages to PST Files showed how to add messages to PST files. It is, of course, also possible to delete items (contents) from a PST file and it may also be desirable to delete messages in bulk. Items from a PST file can be deleted using the FolderInfo.DeleteC
    // Enter here the actual content of the snippet.            
    //Deleting Messages from PST Files
    
    //The code snippets below delete messages from a PST file's Sent subfolder.
    
    //[C# Code Sample]
    
    // Get the Sent items folder
    FolderInfo folderInfo = pst.GetPredefinedFolder(StandardIpmFolder.SentItems);
    MessageInfoCollection msgInfoColl = folderInfo.GetContents();
    foreach (MessageInfo msgInfo in msgInfoColl)
    {
        Console.WriteLine(msgInfo.Subject + ": " + msgInfo.EntryIdString);
        if (msgInfo.Subject.Equals("some delete condition") == true)
        {
            // Delete this item
            folderInfo.DeleteChildItem(msgInfo.EntryId);
            Console.WriteLine("Deleted this message");
        }
    }
     
    //[VB.NET Code Sample]
    
    ' Get the Sent items folder
    Dim folderInfo As FolderInfo = pst.GetPredefinedFolder(StandardIpmFolder.SentItems)
    Dim msgInfoColl As MessageInfoCollection = folderInfo.GetContents()
    For Each msgInfo As MessageInfo In msgInfoColl
    	Console.WriteLine(msgInfo.Subject & ": " & msgInfo.EntryIdString)
    	If msgInfo.Subject.Equals("some delete condition") = True Then
    		' Delete this item
    		folderInfo.DeleteChildItem(msgInfo.EntryId)
    		Console.WriteLine("Deleted this message")
    	End If
    Next msgInfo
    
    //Delete Items in Bulk from PST File
    
    //Aspose.Email API can be used to delete items in bulk from a PST file. This is achieved using the DeleteChildItems method which accepts a list of Entry ID items referring to the items to be deleted.
    
    //[C# Code Sample]
    
    using (PersonalStorage pst = PersonalStorage.FromFile(@"test.pst"))
    {
        FolderInfo inbox = pst.RootFolder.GetSubFolder("Inbox");
        
        // find messages having From = "someuser@domain.com" 
        PersonalStorageQueryBuilder queryBuilder = new PersonalStorageQueryBuilder();
        queryBuilder.From.Contains("someuser@domain.com");
        MessageInfoCollection messages = inbox.GetContents(queryBuilder.GetQuery());
        IList<string> deleteList = new List<string>();
        foreach (MessageInfo messageInfo in messages)
        {
            deleteList.Add(messageInfo.EntryIdString);
        }
        
        // delete messages having From = "someuser@domain.com"
        inbox.DeleteChildItems(deleteList);
    }
    
    //[VB.NET Code Sample]
    
    Using pst As PersonalStorage = PersonalStorage.FromFile("test.pst")
    	Dim inbox As FolderInfo = pst.RootFolder.GetSubFolder("Inbox")
    
    	' find messages having From = "someuser@domain.com" 
    	Dim queryBuilder As New PersonalStorageQueryBuilder()
    	queryBuilder.From.Contains("someuser@domain.com")
    	Dim messages As MessageInfoCollection = inbox.GetContents(queryBuilder.GetQuery())
    	Dim deleteList As IList(Of String) = New List(Of String)()
    	For Each messageInfo As MessageInfo In messages
    		deleteList.Add(messageInfo.EntryIdString)
    	Next
    
    	' delete messages having From = "someuser@domain.com"
    	inbox.DeleteChildItems(deleteList)
    End Using
    
    

    public by sherazam  3271  2  5  1

    How to Copy Message from One Mailbox Folder to Another in .NET Apps

    This technical tip explains how .NET developers can Copy Message from one Mailbox folder to another. Aspose.Email API provides the capability to copy message from one mailbox folder to another. It allows copying a single as well as multiple messages using the CopyMessage and CopyMessages methods. The CopyMessages method provides the capability to c
    // Enter here the actual content of the snippet.     //Copying Multiple Messages From One Folder to Another
    
    //[C# Code Sample]
    
    using (ImapClient client = new ImapClient("exchange.aspose.com", "username", "password" ))
    {
        //create the destination folder
        string folderName = "EMAILNET-35242";
        if (!client.ExistFolder(folderName))
            client.CreateFolder(folderName);
    
        try
        {
            //Append a couple of messages to the server
            MailMessage message1 = new MailMessage(
                "asposeemail.test3@aspose.com",
                "asposeemail.test3@aspose.com",
                "EMAILNET-35242 - " + Guid.NewGuid().ToString(),
                "EMAILNET-35242 Improvement of copy method.Add ability to 'copy' multiple messages per invocation.");
            string uniqueId1 = client.AppendMessage(message1);
    
            MailMessage message2 = new MailMessage(
                "asposeemail.test3@aspose.com",
                "asposeemail.test3@aspose.com",
                "EMAILNET-35242 - " + Guid.NewGuid().ToString(),
                "EMAILNET-35242 Improvement of copy method.Add ability to 'copy' multiple messages per invocation.");
            string uniqueId2 = client.AppendMessage(message2);
    
            //verify that the messages have been added to the mailbox
            client.SelectFolder(ImapFolderInfo.InBox);
            ImapMessageInfoCollection msgsColl = client.ListMessages();
            foreach (ImapMessageInfo msgInfo in msgsColl)
                Console.WriteLine(msgInfo.Subject);
    
            //copy multiple messages using hte CopyMessages command
            client.CopyMessages(new string[] { uniqueId1, uniqueId2 }, folderName, true);
    
            //Verify that messages are copied to the destination folder
            client.SelectFolder(folderName);
            msgsColl = client.ListMessages();
            foreach (ImapMessageInfo msgInfo in msgsColl)
                Console.WriteLine(msgInfo.Subject);
        }
        finally
        {
            try {
                client.DeleteFolder(folderName);
            }
            catch { }
        }
    }
     
    //[VB.NET Code Sample]
    
    Using client As New ImapClient("exchange.aspose.com", "username", "password")
    	'create the destination folder
    	Dim folderName As String = "EMAILNET-35242"
    	If Not client.ExistFolder(folderName) Then
    		client.CreateFolder(folderName)
    	End If
    
    	Try
    		'Append a couple of messages to the server
    		Dim message1 As New MailMessage("asposeemail.test3@aspose.com", "asposeemail.test3@aspose.com", "EMAILNET-35242 - " + Guid.NewGuid().ToString(), "EMAILNET-35242 Improvement of copy method.Add ability to 'copy' multiple messages per invocation.")
    		Dim uniqueId1 As String = client.AppendMessage(message1)
    
    		Dim message2 As New MailMessage("asposeemail.test3@aspose.com", "asposeemail.test3@aspose.com", "EMAILNET-35242 - " + Guid.NewGuid().ToString(), "EMAILNET-35242 Improvement of copy method.Add ability to 'copy' multiple messages per invocation.")
    		Dim uniqueId2 As String = client.AppendMessage(message2)
    
    		'verify that the messages have been added to the mailbox
    		client.SelectFolder(ImapFolderInfo.InBox)
    		Dim msgsColl As ImapMessageInfoCollection = client.ListMessages()
    		For Each msgInfo As ImapMessageInfo In msgsColl
    			Console.WriteLine(msgInfo.Subject)
    		Next
    
    		'copy multiple messages using hte CopyMessages command
    		client.CopyMessages(New String() {uniqueId1, uniqueId2}, folderName, True)
    
    		'Verify that messages are copied to the destination folder
    		client.SelectFolder(folderName)
    		msgsColl = client.ListMessages()
    		For Each msgInfo As ImapMessageInfo In msgsColl
    			Console.WriteLine(msgInfo.Subject)
    		Next
    	Finally
    		Try
    			client.DeleteFolder(folderName)
    		Catch
    		End Try
    	End Try
    End Using
    
           

    List Complete ( 2 snippets total )

    Cannot find what you were looking for?
    Ask the Snip2Code Community

    • Public Snippets
    • Channels Snippets