Python'da IMAP Mesajlarını Yedekleme ve Geri Yükleme
Aspose.Email for Python, şunun yöntemlerini sunar: ImapClient IMAP protokolü üzerinden e-posta mesajlarını yönetmek için sınıf:
- ‘backup’ metodu
- ‘restore’ metodu
Bu makale, şunun kullanımını göstermektedir: ImapClient sınıf ve yöntemleri, e-posta mesajlarını bir PST dosyasına yedeklemek ve geri yüklemek için. Ayrıca, çoklu bağlantı modu kullanarak büyük posta kutularının performansını nasıl artıracağını da kapsar.
IMAP Mesajlarını Yedekleme
Bir IMAP sunucusundan e-posta mesajlarını yedeklemek için şunu kullanın: backup metodu ImapClient sınıf. Aşağıdaki kod örneği, Inbox klasörünü bir .pst dosyasına yedeklemeyi gösterir:
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 Mesajlarını Geri Yükleme
.pst dosyasından mesajları bir IMAP sunucusuna geri yüklemek için şunu kullanın: restore metodu ImapClient sınıf:
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)
Multi-Connection Modu ile Performansı Artırma
Büyük miktarda veri veya çok sayıda e-posta mesajı içeren görevler için Aspose.Email, … ‘use_multi_connection’ özelliğini sunar. ImapClient sınıf, istemcinin e-posta sunucusuna aynı anda birden fazla bağlantı açarak işlemlerin performansını optimize eder. Ne zaman MultiConnectionMode etkinleştirildiğinde, IMAP istemcisi farklı bağlantılar üzerinden çeşitli görevleri (e-posta çekme, klasör senkronizasyonu ve veri yedekleme gibi) paralel olarak yürütebilir. Bu, işlemlerin tamamlanması için gereken toplam sürede önemli bir azalma sağlayabilir. Aşağıdaki kod örnekleri, nasıl etkinleştirileceğini gösterir MultiConnection yedekleme ve geri yükleme işlemleri için mod.
Not: Çoklu bağlantı kullanımı, e-posta sunucusu tarafından belirlenen sınırlamalara ve politikalara tabi olabilir. Bazı sunucular, sunucunun aşırı yüklenmesini önlemek için tek bir kullanıcı hesabından yapılabilecek eşzamanlı bağlantı sayısına sınırlama getirebilir. MultiConnectionMode’u etkinleştirmeden önce hizmet şartlarını veya e-posta sağlayıcısının politikalarını kontrol ederek kullanım yönergelerine uyduğunuzdan emin olun.
MultiConnection Etkinleştirilmiş Yedekleme Mesajları
Aşağıdaki kod parçacığı, MultiConnection modu etkinleştirilmiş bir yedekleme işleminin nasıl yapılacağını gösterir:
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)
Çoklu Bağlantı ile Mesajları Geri Yükle
Aşağıdaki kod parçacığı, MultiConnection modu etkinleştirilmiş bir geri yükleme işleminin nasıl yapılacağını gösterir.
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)