IMAP back‑up en herstelbewerking
Standaard backup en restore
Aspose.Email voor .NET biedt de mogelijkheid om berichten te back-uppen en te herstellen. Hiervoor levert de API de volgende methoden.
Dit artikel laat zien hoe je berichten back‑up en herstelt met behulp van de ImapClient klasse.
Berichten back‑uppen
Om berichten te back‑uppen, gebruik je de ImapClient.Backup methode zoals gedemonstreerd in de volgende code‑snippet.
// 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);
Berichten herstellen
Om berichten te herstellen, gebruik de ImapClient.Restore methode zoals gedemonstreerd in de volgende code‑snippet.
// 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 backup en restore met MultiConnection
Bij het verwerken van een groot aantal berichten kan de back‑up-/herstelbewerking veel tijd in beslag nemen. Daarom biedt de API ondersteuning voor meerdere verbindingen tijdens back‑up en herstel. Om de MultiConnection‑modus in te schakelen, stel je ImapClient.UseMultiConnection eigenschap om MultiConnectionMode.Enable. De volgende code‑snippets demonstreren back‑up‑ en herstelbewerking met MultiConnection‑modus ingeschakeld.
De volgende code‑snippets demonstreren de backup‑bewerking met MultiConnection-modus ingeschakeld.
// 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);
De volgende code‑snippets demonstreren de restore‑bewerking met MultiConnection-modus ingeschakeld.
// 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);