Retrieve subject line of all Email messages

Author Johnny Josefsson on February 19, 2010 | Print | Bookmark
## Load dependency assemblies
#
[System.Reflection.Assembly]::LoadFile("C:\WINDOWS\System32\ChilkatDotNet2.dll")

## Define error handling in script
#
$ErrorActionPreference = "Inquire"

## Define global variables
#
$global__FromAddress = "user@server"
$global__SMTPAuth    = 0
$global__SMTPUsing   = 2
$global__SMTPPort    = 25
$global__SMTPServer  = "smtp-server"
$global__POP3Port    = 110
$global__POP3Server  = "pop3-server"
$global__MailLogin   = "user"
$global__MailPaswd   = "password"


    #create object
$obj = New-Object "Chilkat.MailMan"

    #unlock component
$objUnlockKey = "Start my 30-day Trial"

    #verify status
$objUnlockStatus = $obj.UnlockComponent($objUnlockKey) 
if($objUnlockStatus -eq 0)
{
    Write-Host "main: Unable to unlock the Chilkat.MailMan component"
    Break
}

    #define mail host
$obj.MailHost = $global__POP3Server

    #define mail user name
$obj.PopUsername = $global__MailLogin

    #define user password
$obj.PopPassword = $global__MailPaswd

    #get unique ids of all mails
$strRequests = $obj.GetUidls()
if($strRequests -eq 0)
{
    Write-Host "main: No email exists"
    Break
}

    #loop through all emails an retrieve the subject
for ($i = 0; $i -le $strRequests.Count; $i++)
{
  $objEmail = $obj.FetchEmail($strRequests.GetString($i))
  
  Write-Host $objEmail.Subject
}


    # end POP3 server session
$obj.Pop3EndSession()

Was this article helpful?

Yes No

Category: Scripting, PowerShell

Last updated on April 20, 2010 with 1228 views