Get Gmail message id

Gmail provides a unique message ID for each email so that a unique message may be identified across multiple folders.

Retrieval of this message ID is supported via the X-GM-MSGID attribute on the FETCH command.

The message ID is a 64-bit unsigned integer.

// C# version

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

    imap.SelectInbox();

    List<long> uids = imap.GetAll();
    List<messageInfo> infos = imap.GetMessageInfoByUID(uids);

    foreach (MessageInfo info in infos)
    {
        Console.WriteLine("{0} - {1}",
            info.Envelope.GmailMessageId,
            info.Envelope.Subject);
    }

    imap.Close();
}
' VB.NET version

Using imap As New Imap()
	imap.ConnectSSL("imap.gmail.com")
	imap.UseBestLogin("pat@gmail.com", "password")

	imap.SelectInbox()

	Dim uids As List(Of Long) = imap.GetAll()
	Dim infos As List(Of MessageInfo) = imap.GetMessageInfoByUID(uids)

	For Each info As MessageInfo In infos
	    Console.WriteLine("{0} - {1}", _
                info.Envelope.GmailMessageId, _
                info.Envelope.Subject)
	Next

	imap.Close()
End Using

You can learn more about this Gmail IMAP extension here:
http://code.google.com/apis/gmail/imap/#x-gm-msgid

Tags:      

Questions?

Consider using our Q&A forum for asking questions.

One Response to “Get Gmail message id”

  1. Gmail extensions in Mail.dll Says:

    […] Get Gmail message id […]