Sample code for 30+ languages & platforms
PowerShell

List Email UIDs

List the UIDs of each email in a mailbox.

Chilkat PowerShell Downloads

PowerShell
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

$imap = New-Object Chilkat.Imap

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

# Connect to an IMAP server.
# Use TLS
$imap.Ssl = $true
$imap.Port = 993
$success = $imap.Connect("MY-IMAP-DOMAIN")
if ($success -eq $false) {
    $($imap.LastErrorText)
    exit
}

# Login
$success = $imap.Login("MY-IMAP-LOGIN","MY-IMAP-PASSWORD")
if ($success -eq $false) {
    $($imap.LastErrorText)
    exit
}

# Select an IMAP mailbox
$success = $imap.SelectMailbox("Inbox")
if ($success -eq $false) {
    $($imap.LastErrorText)
    exit
}

# Get the message IDs of all the emails in the mailbox
# We can choose to fetch UIDs or sequence numbers.
$fetchUids = $true
$messageSet = New-Object Chilkat.MessageSet
$success = $imap.QueryMbx("ALL",$fetchUids,$messageSet)
if ($success -eq $false) {
    $($imap.LastErrorText)
    exit
}

$i = 0
$n = $messageSet.Count
while ($i -lt $n) {
    $($messageSet.GetId($i))
    $i = $i + 1
}

# Disconnect from the IMAP server.
$success = $imap.Disconnect()