IMAP バックアップおよびリストア操作

標準的なバックアップと復元

Aspose.Email for .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 のバックアップと復元

大量のメッセージを扱う場合、バックアップ/リストア操作に時間がかかることがあります。そのため、API はバックアップおよびリストア時に複数の接続をサポートします。マルチ接続モードを有効にするには、次の設定を行います。 ImapClient.UseMultiConnection プロパティ MultiConnectionMode.Enable。以下のコードスニペットは、マルチ接続モードを有効にした状態でのバックアップおよびリストア操作を示します。

以下のコードスニペットは、マルチコネクションモードが有効な バックアップ操作 を示しています。

// 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);

以下のコードスニペットは、マルチコネクションモードが有効な 復元操作 を示しています。

// 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);