How can we help?

Using Auron Email Component in PowerShell


The E-mail Component is ready to be used in Powershell without any extra configuration steps.

The example script below lists any unseen e-mail messages through IMAP using the E-mail Component API in PowerShell.

To run this script just copy and past it into notepad and save it as ‘receiveimap.ps1‘.

Open up a PowerShell prompt. Navigate to the directory where the script was saved. Run the script in PowerShell using the command: ‘.\receiveimap.ps1

$objImap = new-object -comobject AxEmail.Imap
$objConstants = new-object -comobject AxEmail.Constants

# Display E-mail Component Version
write-host Auron E-mail Component $objImap.Version
write-host Build: $objImap.Build `nModule: $objImap.Module

# Connect to the IMAP server
$objImap.Connect("mail.mycompany.com", "me@mycompany.com", "p@ssword")
write-host Connect, result: $objImap.LastError `
  ($objImap.GetErrorDescription($objImap.LastError))

# Fetch email header info for all unseen messages in the default mailbox ('INBOX')
$objEmail = $objImap.FetchFirstEmailHeader($objConstants.IMAP_SK_UNSEEN)
while ($objImap.LastError -eq 0)
{
write-host MessageID : $objEmail.ImapUID
write-host From : $objEmail.FromAddress
write-host From Name : $objEmail.FromName
write-host To : $objEmail.ToAddress
write-host Subject : $objEmail.Subject
write-host Date : $objEmail.Date
write-host

$objEmail = $objImap.FetchNextEmailHeader()
}

#Disconnect
$objImap.Disconnect()
write-host Disconnected.
write-host Ready.
exit