Операция за архивиране и възстановяване с IMAP
Стандартно архивиране и възстановяване
Aspose.Email за .NET предоставя възможност за архивиране и възстановяване на съобщения. За това API‑тът предоставя следните методи.
Тази статия демонстрира как да архивирате и възстановявате съобщения, използвайки ImapClient клас.
Архивиране на съобщения
За архивиране на съобщения, използвайте ImapClient.Backup метод, както е демонстрирано в следния откъс от код.
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_IMAP();
// Create an instance of the ImapClient class
ImapClient imapClient = new ImapClient();
// Specify host, username and password, and set port for your client
imapClient.Host = "imap.gmail.com";
imapClient.Username = "your.username@gmail.com";
imapClient.Password = "your.password";
imapClient.Port = 993;
imapClient.SecurityOptions = SecurityOptions.Auto;
ImapMailboxInfo mailboxInfo = imapClient.MailboxInfo;
ImapFolderInfo info = imapClient.GetFolderInfo(mailboxInfo.Inbox.Name);
ImapFolderInfoCollection infos = new ImapFolderInfoCollection();
infos.Add(info);
imapClient.Backup(infos, dataDir + @"\ImapBackup.pst", BackupOptions.Recursive);
Възстановяване на съобщения
За да възстановите съобщения, използвайте ImapClient.Restore метод, както е демонстрирано в следния откъс от код.
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_IMAP();
// Create an instance of the ImapClient class
ImapClient imapClient = new ImapClient();
// Specify host, username and password, and set port for your client
imapClient.Host = "imap.gmail.com";
imapClient.Username = "your.username@gmail.com";
imapClient.Password = "your.password";
imapClient.Port = 993;
imapClient.SecurityOptions = SecurityOptions.Auto;
RestoreSettings settings = new RestoreSettings();
settings.Recursive = true;
PersonalStorage pst = PersonalStorage.FromFile(dataDir + @"\ImapBackup.pst");
imapClient.Restore(pst, settings);
IMAP архивиране и възстановяване с MultiConnection
Когато работите с голям брой съобщения, операцията по архивиране/възстановяване може да отнеме много време. За това API‑то предоставя поддръжка за множество връзки по време на операцията за архивиране и възстановяване. За да активирате MultiConnection режима, задайте ImapClient.UseMultiConnection свойство за MultiConnectionMode.Enable. Следните откъси от код демонстрират операции за архивиране и възстановяване с активиран MultiConnection режим.
Следните фрагменти от код демонстрират операция по архивиране с активиран режим MultiConnection.
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_IMAP();
// Create an instance of the ImapClient class
ImapClient imapClient = new ImapClient();
// Specify host, username and password, and set port for your client
imapClient.Host = "imap.gmail.com";
imapClient.Username = "your.username@gmail.com";
imapClient.Password = "your.password";
imapClient.Port = 993;
imapClient.SecurityOptions = SecurityOptions.Auto;
imapClient.UseMultiConnection = MultiConnectionMode.Enable;
ImapMailboxInfo mailboxInfo = imapClient.MailboxInfo;
ImapFolderInfo info = imapClient.GetFolderInfo(mailboxInfo.Inbox.Name);
ImapFolderInfoCollection infos = new ImapFolderInfoCollection();
infos.Add(info);
imapClient.Backup(infos, dataDir + @"\ImapBackup.pst", BackupOptions.Recursive);
Следните фрагменти от код демонстрират операция по възстановяване с активиран режим MultiConnection.
// The path to the File directory.
string dataDir = RunExamples.GetDataDir_IMAP();
// Create an instance of the ImapClient class
ImapClient imapClient = new ImapClient();
// Specify host, username and password, and set port for your client
imapClient.Host = "imap.gmail.com";
imapClient.Username = "your.username@gmail.com";
imapClient.Password = "your.password";
imapClient.Port = 993;
imapClient.SecurityOptions = SecurityOptions.Auto;
imapClient.UseMultiConnection = MultiConnectionMode.Enable;
RestoreSettings settings = new RestoreSettings();
settings.Recursive = true;
PersonalStorage pst = PersonalStorage.FromFile(dataDir + @"\Outlook.pst");
imapClient.Restore(pst, settings);