Message Flags
The IMAP protocol allows users to associate flags to email messages. These flags define various message states, for example if a message can be read or not.
GemBox.Email supports getting, adding, updating and removing the message flags, using C# and VB.NET applications. To make it easier, the names of commonly used flags are available to you through ImapMessageFlags
static fields.
Besides working with just a single message's flags (such as ImapClient.AddMessageFlags
methods), you can also process the flags for a group of messages with methods that accept the message range, by defining the start and end message number (such as ImapClient.AddMessageRangeFlags
methods).
In the example below you can see how to read, add, and delete message flags on IMAP.

using System;
using System.Collections.Generic;
using GemBox.Email;
using GemBox.Email.Imap;
class Program
{
static void Main()
{
// If using the Professional version, put your serial key below.
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
using (ImapClient imap = new ImapClient("<ADDRESS> (e.g. imap.gmail.com)"))
{
imap.Connect();
imap.Authenticate("<USERNAME>", "<PASSWORD>");
// Select INBOX folder.
imap.SelectInbox();
// Add "Draft" flag to first message.
imap.AddMessageFlags(1, ImapMessageFlags.Draft);
// Get first message flags and display them.
// Notice the presence of "Draft" flag.
IList<string> flags = imap.GetMessageFlags(1);
foreach (string flag in flags)
Console.WriteLine(flag);
// Remove "Draft" flag from first message.
imap.RemoveMessageFlags(1, ImapMessageFlags.Draft);
Console.WriteLine(new string('-', 10));
// Again, get first message flags and display them.
// Notice the absence of "Draft" flag.
flags = imap.GetMessageFlags(1);
foreach (string flag in flags)
Console.WriteLine(flag);
}
}
}
Imports System
Imports System.Collections.Generic
Imports GemBox.Email
Imports GemBox.Email.Imap
Module Program
Sub Main()
' If using the Professional version, put your serial key below.
ComponentInfo.SetLicense("FREE-LIMITED-KEY")
Using imap As New ImapClient("<ADDRESS> (e.g. imap.gmail.com)")
imap.Connect()
imap.Authenticate("<USERNAME>", "<PASSWORD>")
' Select INBOX folder.
imap.SelectInbox()
' Add "Draft" flag to first message.
imap.AddMessageFlags(1, ImapMessageFlags.Draft)
' Get first message flags and display them.
' Notice the presence of "Draft" flag.
Dim flags As IList(Of String) = imap.GetMessageFlags(1)
For Each flag As String In flags
Console.WriteLine(flag)
Next
' Remove "Draft" flag from first message.
imap.RemoveMessageFlags(1, ImapMessageFlags.Draft)
Console.WriteLine(New String("-"c, 10))
' Again, get first message flags and display them.
' Notice the absence of "Draft" flag.
flags = imap.GetMessageFlags(1)
For Each flag As String In flags
Console.WriteLine(flag)
Next
End Using
End Sub
End Module
For more information about ImapClient
, check out our IMAP Client Connection example.