IMAP 拡張機能を有効にする
Contents
[
Hide
]
IMAP 拡張機能のサポート
Aspose.Email API は、さまざまな IMAP プロトコル拡張をサポートしています。これらの拡張により、クライアントアプリケーションの識別や詳細なメールボックスメタデータの取得などの高度な操作が可能になります。すべてのメールサーバーがこれらの機能をサポートしているわけではありませんが、Gmail などの多くの一般的なサービスは対応しています。
この記事では、次の IMAP 拡張機能の使用方法を示します。 ImapClient Aspose.Email のクラス:
-
IMAP ID コマンド
-
IMAP LIST-EXTENDED コマンド
IMAP ID コマンドの使用
このコマンドは、サーバーが IMAP ID 拡張機能をサポートしているかどうかをフィードバックし、サーバーから構造化された識別情報を返します。ログ取得、診断、サーバーの動作カスタマイズに役立ちます。
以下のコードサンプルは、Aspose.Email ライブラリを使用して IMAP サーバーとやり取りし、特に ID コマンドを使用してサーバーの識別情報を取得する方法を示しています。
import aspose.email as ae
with ae.clients.imap.ImapClient("imap.gmail.com", 993, "username", "password") as client:
# Set security options
client.security_options = ae.clients.SecurityOptions.AUTO
# Check if ID command is supported
print(client.id_supported)
# Send identification info to the server
server_identification_info1 = client.introduce_client()
server_identification_info2 = client.introduce_client(ae.clients.imap.ImapIdentificationInfo.default_value)
# Display server response
print(server_identification_info1)
print(server_identification_info2)
print(server_identification_info1.name)
print(server_identification_info1.vendor)
print(server_identification_info1.support_url)
print(server_identification_info1.version)
IMAP LIST-EXTENDED コマンドの使用
IMAP LIST-EXTENDED コマンド(RFC 5258 で定義)は、クライアントがフォルダー階層やメタデータ(フォルダーに子フォルダーがあるかどうかなど)の詳細を取得できるようにします。これは、複雑なメールボックス構造を管理するクライアントに特に有用です。
以下のコードサンプルは、拡張 LIST コマンドを使用して Gmail のフォルダーを一覧表示し、どのフォルダーにサブフォルダーが含まれているかを確認する方法を示しています。
import aspose.email as ae
with ae.clients.imap.ImapClient("imap.gmail.com", 993, "username", "password") as client:
folder_info_col = client.list_folders("*")
print("Extended List Supported:", client.extended_list_supported)
for folder_info in folder_info_col:
folder_name = folder_info.name
if folder_name == "[Gmail]/All Mail":
print("Has Children:", folder_info.has_children)
elif folder_name == "[Gmail]/Bin":
print("Bin has children?", folder_info.has_children)
elif folder_name == "[Gmail]/Drafts":
print("Drafts has children?", folder_info.has_children)
elif folder_name == "[Gmail]/Important":
print("Important has Children?", folder_info.has_children)
elif folder_name == "[Gmail]/Sent Mail":
print("Sent Mail has Children?", folder_info.has_children)
elif folder_name == "[Gmail]/Spam":
print("Spam has Children?", folder_info.has_children)
elif folder_name == "[Gmail]/Starred":
print("Starred has Children?", folder_info.has_children)