(PowerShell) Upload (Append) Email to an IMAP Mailbox
Upload / append an email to an IMAP mailbox.
Add-Type -Path "C:\chilkat\ChilkatDotNet47-9.5.0-x64\ChilkatDotNet47.dll"
# 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.someMailServer.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()
|