เปิดใช้งานส่วนขยาย IMAP
การสนับสนุนส่วนขยาย IMAP
API ของ Aspose.Email รองรับส่วนขยายหลายประเภทของโปรโตคอล 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) ช่วยให้ไคลเอนต์ดึงข้อมูลโครงสร้างโฟลเดอร์และเมตาดาต้าอย่างละเอียด เช่นว่าโฟลเดอร์มีโฟลเดอร์ย่อยหรือไม่ สิ่งนี้มีประโยชน์โดยเฉพาะสำหรับไคลเอนต์ที่จัดการโครงสร้างกล่องจดหมายที่ซับซ้อน
ตัวอย่างโค้ดต่อไปนี้แสดงวิธีการแสดงรายการโฟลเดอร์ใน Gmail โดยใช้คำสั่ง LIST ที่ขยายและตรวจสอบว่าโฟลเดอร์ใดมีโฟลเดอร์ย่อย:
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)