+1 vote

Does Mail.dll enable setting Gmail Labels on the server?

by

1 Answer

0 votes
 
Best answer

For the purposes of IMAP Gmail treats labels as regular folders.

This means that labels can be modified using standard IMAP commands for folder manipulation, CreateFolder, RenameFolder, and DeleteFolder.

You can also move or copy a message to specified folder (label), which is equivalent of adding such label to the email.

Labels may be also added to a mail message using the STORE command in conjunction with the X-GM-LABELS attribute. This is definitely easier way as you only need to use Imap.GmailLabelMessageByUID method:

using (Imap imap = new Imap())
{
    imap.ConnectSSL("imap.gmail.com");
    imap.UseBestLogin("pat@gmail.com", "password");

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

    imap.GmailLabelMessageByUID(uid, "MyLabel");

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

    imap.Close();
}

System labels are reserved and prefixed with "[Gmail]" or "[GoogleMail]" in the list of labels.

If you want to add system label, such as \Starred or \Important use FolderFlag static properties:

imap.GmailLabelMessageByUID(last, FolderFlag.XStarred.Name);

References:
- https://www.limilabs.com/blog/label-message-with-gmail-label
- https://www.limilabs.com/blog/label-message-with-gmail-system-label-starred

by (301k points)
...