+1 vote

Hello,

Is it possible to download the complete messages to file server for archive purposes?
Is there an example available?

by

1 Answer

0 votes
 
Best answer

Of course it's possible.

When you use GetMessageByUID entire message is downloaded (including
attachments).

Good place to start is:
https://www.limilabs.com/blog/receive-unseen-emails-using-imap
To download all messages use imap.GetAll() instead of imap.Search(Flag.Unseen)

This won't save your folder structure/labels of course.

For Gmail best approach to save all messages including labels and flags is:

Backup:
- use AllMail folder (imap.Select(new CommonFolders(imap.GetFolders()).AllMail))
- use imap.GetMessageInfoByUID to get labels, flags and internal date for each message
- download every message from this folder

Restore:
- use AllMail folders
- upload each message (specify flags and internal server date for each message)
- apply stored labels (imap.GmailLabelMessageByUID)

You can find many samples here:
https://www.limilabs.com/mail/samples

by (297k points)
...