Sample code for 30+ languages & platforms
PowerShell

Upload (Append) Email to an IMAP Mailbox

Upload / append an email to an IMAP mailbox.

Chilkat PowerShell Downloads

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

$success = $false

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

$imap = New-Object Chilkat.Imap

# Connect to an IMAP server.
# Use TLS
$imap.Ssl = $true
$imap.Port = 993
$success = $imap.Connect("imap.example.com")
if ($success -ne $true) {
    $($imap.LastErrorText)
    exit
}

# Login
$success = $imap.Login("myLogin","myPassword")
if ($success -ne $true) {
    $($imap.LastErrorText)
    exit
}

$email = New-Object Chilkat.Email

# Load the email from a .eml file.
$success = $email.LoadEml("myEmail.eml")
if ($success -ne $true) {
    $($email.LastErrorText)
    exit
}

$success = $imap.AppendMail("Inbox",$email)
if ($success -ne $true) {
    $($imap.LastErrorText)
    exit
}

$("Email uploaded to Inbox!")

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