Working with Message Flags on Server
Contents
[
Hide
]
Changing the Message Flags
You can change message flags by using the ChangeMessageFlags() method. This method takes two parameters.
- The message’s sequence number or unique ID.
- MessageFlag.
The following flags can be set:
Setting Message Flags
The following code snippet shows you how to change message flags on an IMAP server with Aspose.Email.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Mark the message as read | |
client.ChangeMessageFlags(1, ImapMessageFlags.IsRead); |
Removing Message Flags
Message flags can also be removed with the RemoveMessageFlags() method. Usage is similar to that of the ChangeMessageFlags() method. It takes a sequence number or unique message ID and MessageFlag. The following code snippet shows you how to remove message flags.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Remove the message flag | |
client.RemoveMessageFlags(1, ImapMessageFlags.IsRead); |
Setting Custom Flags
You can also set custom flags to a message using the ImapClient of the API. The ImapClient’s AddMessageFlags provides the ability to set custom flags on messages.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create a message | |
MailMessage message = new MailMessage("user@domain1.com", "user@domain2.com", "subject", "message"); | |
//Append the message to mailbox | |
string uid = client.AppendMessage(ImapFolderInfo.InBox, message); | |
//Add custom flags to the added messge | |
client.AddMessageFlags(uid, ImapMessageFlags.Keyword("custom1") | ImapMessageFlags.Keyword("custom1_0")); | |
//Retreive the messages for checking the presence of custom flag | |
client.SelectFolder(ImapFolderInfo.InBox); | |
ImapMessageInfoCollection messageInfos = client.ListMessages(); | |
foreach (var inf in messageInfos) | |
{ | |
ImapMessageFlags[] flags = inf.Flags.Split(); | |
if (inf.ContainsKeyword("custom1")) | |
Console.WriteLine("Keyword found"); | |
} | |