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