Label message with Gmail label

If you want to use system label, such as \Starred or \Important please read label message with system label.

Gmail treats labels as folders for the purposes of IMAP.

As such, labels can be modified using the standard IMAP commands, CreateFolder, RenameFolder, and DeleteFolder, that act on folders.

System labels, which are labels created by Gmail, are reserved and prefixed by “[Gmail]” or “[GoogleMail]” in the list of labels.

Use the XLIST command to get the entire list of labels for a mailbox.

The labels for a given message may be retrieved by using the X-GM-LABELS attribute with the FETCH command.

Labels may be added to a message using the STORE command in conjunction with the X-GM-LABELS attribute.

// C# version

using (Imap imap = new Imap())
    imap.UseBestLogin("", "password");

    long uid = imap.GetAll().Last();

    imap.GmailLabelMessageByUID(uid, "MyLabel");

    List<string> labels = imap.GmailGetLabelsByUID(uid);

' VB.NET version

Using imap As New Imap()
	imap.UseBestLogin("", "password")

	Dim uid As Long = imap.GetAll().Last()

	imap.GmailLabelMessageByUID(uid, "MyLabel")

	Dim labels As List(Of String) = imap.GmailGetLabelsByUID(uid)

End Using

You can learn more about this Gmail IMAP extension here:



Consider using our Q&A forum for asking questions.

One Response to “Label message with Gmail label”

  1. Gmail extensions in Mail.dll | Blog | Limilabs Says:

    […] Label message with Gmail label […]