+1 vote

What a brilliant set of email libraries! Our app has only previously been able to automate Outlook, so your product means we can now use GMail. Thanks very much for making this!

Question: I create a draft email, with this:

imap.UploadMessage("[Gmail]/Drafts", email);

Now I want my program to navigate to that draft email in my browser. Does UploadMessage have anyway to return the ID or URL for my draft message?

by
retagged by

1 Answer

0 votes
 
Best answer

Use CommonFolder class as draft folder may have a different name if Gmail is configured to use different UI language:

CommonFolders folders = new CommonFolders(imap.GetFolders());
imap.Select(folders.Draft);
imap.UploadMessage(email);

I want my program to navigate to that draft email in my browser.
Yes, this is possible.

You need to obtain Gmail thread ID for this message (X-GM-THRID Gmail's extension to IMAP):

long uploaded = (long)imap.UploadMessage(email);
MessageInfo info = client.GetMessageInfoByUID(uploaded);
decimal threadId = info.Envelope.GmailThreadId;

Than convert that to hex:

string threadIdAsHex = threadId.ToString("x");

and build the url:

string url = string.Format(
        "https://mail.google.com/mail/u/0/#draft/{0}",
        threadIdAsHex);

References:
- https://www.limilabs.com/blog/common-imap-folders
- https://www.limilabs.com/blog/create-gmail-url-id-via-imap

by (301k points)
...