Sample code for 30+ languages & platforms
AutoIt Requires Chilkat v11.0.0+

Imap.GetMailSize vs Email.Size

Shows how to get the total size of an email, as well as the sizes of the attachments. This can be done when either full-emails or headers-only are downloaded.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

;  This example assumes the Chilkat API to have been previously unlocked.
;  See Global Unlock Sample for sample code.

$oImap = ObjCreate("Chilkat.Imap")

;  Connect to an IMAP server.
;  Use TLS
$oImap.Ssl = True
$oImap.Port = 993
$bSuccess = $oImap.Connect("imap.example.com")
If ($bSuccess = False) Then
    ConsoleWrite($oImap.LastErrorText & @CRLF)
    Exit
EndIf

;  Login
$bSuccess = $oImap.Login("****","****")
If ($bSuccess = False) Then
    ConsoleWrite($oImap.LastErrorText & @CRLF)
    Exit
EndIf

;  Select an IMAP mailbox
$bSuccess = $oImap.SelectMailbox("Inbox")
If ($bSuccess = False) Then
    ConsoleWrite($oImap.LastErrorText & @CRLF)
    Exit
EndIf

;  Get the message IDs of all the emails in the mailbox
;  We can choose to fetch UIDs or sequence numbers.
Local $bFetchUids = True
$oMessageSet = ObjCreate("Chilkat.MessageSet")
$bSuccess = $oImap.QueryMbx("ALL",$bFetchUids,$oMessageSet)
If ($bSuccess = False) Then
    ConsoleWrite($oImap.LastErrorText & @CRLF)
    Exit
EndIf

;  When downloading headers, each email object contains
;  (obviously) the headers, but the body will be missing.
;  Attachments will not be included.  However, it is
;  possible to get information about the attachments
;  as well as the complete size of the email.
$oBundle = ObjCreate("Chilkat.EmailBundle")
Local $bHeadersOnly = True
$bSuccess = $oImap.FetchMsgSet($bHeadersOnly,$oMessageSet,$oBundle)
If ($bSuccess = False) Then
    ConsoleWrite($oImap.LastErrorText & @CRLF)
    Exit
EndIf

;  Loop over the email objects and display information about each:
$oEmail = ObjCreate("Chilkat.Email")
Local $i = 0
Local $iJ = 0
Local $iNumEmails = $oBundle.MessageCount
While $i < $iNumEmails
    $oBundle.EmailAt($i,$oEmail)

    ;  Display the From and Subject
    ConsoleWrite($oEmail.From & @CRLF)
    ConsoleWrite($oEmail.Subject & @CRLF)

    ;  Display the recipients:
    $iJ = 0
    While $iJ < $oEmail.NumTo
        ConsoleWrite("TO: " & $oEmail.GetToName($iJ) & ", " & $oEmail.GetToAddr($iJ) & @CRLF)
        $iJ = $iJ + 1
    Wend
    $iJ = 0
    While $iJ < $oEmail.NumCC
        ConsoleWrite("CC: " & $oEmail.GetCcName($iJ) & ", " & $oEmail.GetCcAddr($iJ) & @CRLF)
        $iJ = $iJ + 1
    Wend

    ;  Show the total size of the email, including body and attachments:
    ConsoleWrite($oEmail.Size & @CRLF)

    ;  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:
Local $iNumAttach = $oImap.GetMailNumAttach($oEmail)
    $iJ = 0
    While $iJ < $iNumAttach
        ConsoleWrite($oImap.GetMailAttachFilename($oEmail,$iJ) & @CRLF)
Local $iAttachSize = $oImap.GetMailAttachSize($oEmail,$iJ)
        ConsoleWrite("    size = " & $iAttachSize & " bytes" & @CRLF)
        $iJ = $iJ + 1
    Wend

    ConsoleWrite("--" & @CRLF)

    $i = $i + 1
Wend

;  Disconnect from the IMAP server.
$bSuccess = $oImap.Disconnect()