Python में IMAP संदेशों का बैकअप और रिस्टोर
Python के लिए Aspose.Email इस क्लास के मेथड्स प्रदान करता है ImapClient IMAP प्रोटोकॉल पर ईमेल संदेशों का प्रबंधन करने के लिए क्लास:
- ‘backup’ मेथड
- ‘restore’ मेथड
यह लेख दर्शाता है कि कैसे उपयोग करें ImapClient क्लास और इसके मेथड्स PST फ़ाइल में और उससे ईमेल संदेशों का बैकअप और रिस्टोर करने के लिए। यह मल्टी-कनेक्शन मोड का उपयोग करके बड़े मेलबॉक्स के प्रदर्शन को सुधारने के बारे में भी बताता है।
IMAP संदेशों का बैकअप
IMAP सर्वर से ईमेल संदेशों का बैकअप बनाने के लिए, इसका उपयोग करें backup विधि ImapClient क्लास। नीचे दिया गया कोड नमूना दिखाता है कि इनबॉक्स फ़ोल्डर को .pst फ़ाइल में कैसे बैकअप किया जाए:
import aspose.email as ae
# Create an instance of the ImapClient class
imap_client = ae.clients.imap.ImapClient()
# Specify host, username, password, and set port for your client
imap_client.host = "imap.gmail.com"
imap_client.username = username
imap_client.password = password
imap_client.port = 993
imap_client.security_options = ae.clients.SecurityOptions.AUTO
# Get mailbox info
mailbox_info = imap_client.mailbox_info
# Get folder info for the Inbox folder
inbox_info = imap_client.get_folder_info(mailbox_info.inbox.name)
# Create an ImapFolderInfoCollection and add the Inbox folder info
infos = ae.clients.imap.ImapFolderInfoCollection()
infos.add(inbox_info)
# Specify the path to the directory
data_dir = "path/to/your/data/directory"
# Perform the backup operation
settings = ae.clients.imap.BackupSettings
settings.execute_recursively = True
imap_client.backup(infos, data_dir + "\\ImapBackup.pst", settings)
IMAP संदेशों को रिस्टोर करें
.pst फ़ाइल से संदेशों को पुनः IMAP सर्वर में रिस्टोर करने के लिए, इसका उपयोग करें restore विधि ImapClient क्लास:
import aspose.email as ae
# Create an instance of the ImapClient class
imap_client = ae.clients.imap.ImapClient()
# Specify host, username, password, and set port for your client
imap_client.host = "imap.gmail.com"
imap_client.username = username
imap_client.password = password
imap_client.port = 993
imap_client.security_options = ae.clients.SecurityOptions.Auto
# Create RestoreSettings with Recursive set to true
settings = ae.clients.imap.RestoreSettings()
settings.recursive = True
# Specify the path to the directory
data_dir = "path/to/your/data/directory"
# Load the PST file
pst = ae.storage.pst.PersonalStorage.from_file(data_dir + "\\ImapBackup.pst")
# Perform the restore operation
imap_client.restore(pst, settings)
मल्टी-कनेक्शन मोड के साथ प्रदर्शन बढ़ाएँ
बड़े डेटा या कई ईमेल संदेशों के कार्यों के लिए, Aspose.Email ‘use_multi_connection’ प्रॉपर्टी प्रदान करता है ImapClient क्लास जो ऑपरेशनों के प्रदर्शन को अनुकूलित करता है, क्लाइंट को ईमेल सर्वर के साथ समानांतर कई कनेक्शन खोलने की अनुमति देता है। जब MultiConnectionMode सक्षम होने पर, IMAP क्लाइंट विभिन्न कार्य (जैसे ईमेल फेच करना, फ़ोल्डर सिंक्रनाइज़ करना, और डेटा बैकअप) विभिन्न कनेक्शनों में समानांतर रूप से कर सकता है। इससे संचालन को पूरा करने में कुल समय में उल्लेखनीय कमी आ सकती है। नीचे दिए गए कोड स्निपेट दिखाते हैं कि कैसे सक्षम करें MultiConnection बैकअप और रिस्टोर संचालन के लिए मोड।
नोट: कई कनेक्शन का उपयोग इमेल सर्वर द्वारा निर्धारित सीमाओं और नीतियों के अधीन हो सकता है। कुछ सर्वर एकल उपयोगकर्ता खाते से किए जा सकने वाले समानांतर कनेक्शन की संख्या पर प्रतिबंध लगा सकते हैं ताकि सर्वर पर अधिक लोड न हो। MultiConnectionMode को सक्षम करने से पहले हमेशा इमेल प्रदाता की सेवा शर्तों या नीतियों की जांच करें ताकि उनके उपयोग दिशानिर्देशों के साथ अनुपालन सुनिश्चित हो सके।
MultiConnection सक्षम साथ संदेशों का बैकअप
नीचे दिया गया कोड स्निपेट दिखाता है कि MultiConnection मोड सक्षम होने पर बैकअप ऑपरेशन कैसे किया जाए:
import aspose.email as ae
# Create an instance of the ImapClient class
imap_client = ae.clients.imap.ImapClient()
# Specify host, username, password, and set port for your client
imap_client.host = "imap.gmail.com"
imap_client.username = username
imap_client.password = password
imap_client.port = 993
imap_client.security_options = ae.clients.SecurityOptions.Auto
# Enable MultiConnectionMode
imap_client.use_multi_connection = ae.clients.MultiConnectionMode.ENABLE
# Get mailbox info
mailbox_info = imap_client.mailbox_info
# Get folder info for the Inbox folder
inbox_info = imap_client.get_folder_info(mailbox_info.inbox.name)
# Create an ImapFolderInfoCollection and add the Inbox folder info
infos = ae.clients.imap.ImapFolderInfoCollection()
infos.add(inbox_info)
# Specify the path to the directory
data_dir = "path/to/your/data/directory"
# Perform the backup operation
settings = ae.clients.imap.BackupSettings
settings.execute_recursively = True
imap_client.backup(infos, data_dir + "\\ImapBackup.pst", settings)
मल्टीकनेक्शन के साथ संदेशों को रिस्टोर करें
नीचे दिया गया कोड स्निपेट दिखाता है कि MultiConnection मोड सक्षम होने पर रिस्टोर ऑपरेशन कैसे किया जाए।
import aspose.email as ae
# Create an instance of the ImapClient class
imap_client = ae.clients.imap.ImapClient()
# Specify host, username, password, and set port for your client
imap_client.host = "imap.gmail.com"
imap_client.username = username
imap_client.password = password
imap_client.port = 993
imap_client.security_options = ae.clients.SecurityOptions.Auto
# Enable MultiConnectionMode
imap_client.use_multi_connection = ae.clients.MultiConnectionMode.ENABLE
# Create RestoreSettings with Recursive set to true
settings = ae.clients.imap.RestoreSettings()
settings.recursive = True
# Specify the path to the directory
data_dir = "path/to/your/data/directory"
# Load the PST file
pst = ae.storage.pst.PersonalStorage.from_file(data_dir + "\\Outlook.pst")
# Perform the restore operation
imap_client.restore(pst, settings)