Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Tcl) Fetch Single Email by UID or Sequence NumberAssuming the UID is known, download a single email by UID from an IMAP mail server.
load ./chilkat.dll # This example requires the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. set imap [new_CkImap] # Connect to an IMAP server. # Use TLS CkImap_put_Ssl $imap 1 CkImap_put_Port $imap 993 set success [CkImap_Connect $imap "imap.someMailServer.com"] if {$success != 1} then { puts [CkImap_lastErrorText $imap] delete_CkImap $imap exit } # Login set success [CkImap_Login $imap "***" "***"] if {$success != 1} then { puts [CkImap_lastErrorText $imap] delete_CkImap $imap exit } # Select an IMAP mailbox set success [CkImap_SelectMailbox $imap "Inbox"] if {$success != 1} then { puts [CkImap_lastErrorText $imap] delete_CkImap $imap exit } # email is a CkEmail set uid 2014 set isUid 1 set email [CkImap_FetchSingle $imap $uid $isUid] if {[CkImap_get_LastMethodSuccess $imap] == 1} then { # Display the From and Subject puts [CkEmail_fromAddress $email] puts [CkEmail_subject $email] # Display the Body property, which is the default body. # If an email has an HTML body, the Body property contains # the HTML source. Otherwise it contains the plain-text # body. puts "---- EMAIL BODY ----" puts [CkEmail_body $email] puts "--------------------" # Display the recipients: for {set j 0} {$j <= [expr [CkEmail_get_NumTo $email] - 1]} {incr j} { puts [CkEmail_getToName $email $j], [CkEmail_getToAddr $email $j] } for {set j 0} {$j <= [expr [CkEmail_get_NumCC $email] - 1]} {incr j} { puts [CkEmail_getCcName $email $j], [CkEmail_getCcAddr $email $j] } # Show the total size of the email, including body and attachments: puts [CkEmail_get_Size $email] # When a full email is downloaded, we would use the # email.NumAttachments property in conjunction with the # email.GetMailAttach* methods. # However, when an email object contains only the header, # we need to access the attachment info differently: set numAttach [CkImap_GetMailNumAttach $imap $email] puts "$numAttach" for {set j 0} {$j <= [expr $numAttach - 1]} {incr j} { puts [CkImap_getMailAttachFilename $imap $email $j] set attachSize [CkImap_GetMailAttachSize $imap $email $j] puts " size = $attachSize bytes" } puts "--" delete_CkEmail $email } # Disconnect from the IMAP server. set success [CkImap_Disconnect $imap] delete_CkImap $imap |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.